繁体   English   中英

使用python将数据存储到数据库并在node.js应用中检索数据

[英]storing data to database using python and retrieving it in a node.js app

以下代码使用基于图像内容选择的标签(或“标签”)注释视频。

import argparse

from google.cloud import videointelligence


def analyze_labels(path):
    """ Detects labels given a GCS path. """
    video_client = videointelligence.VideoIntelligenceServiceClient()
    features = [videointelligence.enums.Feature.LABEL_DETECTION]
    operation = video_client.annotate_video(path, features=features)
    print('\nProcessing video for label annotations:')

    result = operation.result(timeout=90)
    print('\nFinished processing.')

    segment_labels = result.annotation_results[0].segment_label_annotations
    for i, segment_label in enumerate(segment_labels):
        print('Video label description: {}'.format(
            segment_label.entity.description))
        for category_entity in segment_label.category_entities:
            print('\tLabel category description: {}'.format(
                category_entity.description))

        for i, segment in enumerate(segment_label.segments):
            start_time = (segment.segment.start_time_offset.seconds +
                          segment.segment.start_time_offset.nanos / 1e9)
            end_time = (segment.segment.end_time_offset.seconds +
                        segment.segment.end_time_offset.nanos / 1e9)
            positions = '{}s to {}s'.format(start_time, end_time)
            confidence = segment.confidence
            print('\tSegment {}: {}'.format(i, positions))
            print('\tConfidence: {}'.format(confidence))
        print('\n')


if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('path', help='GCS file path for label detection.')
    args = parser.parse_args()

    analyze_labels(args.path)

该代码将结果打印到终端。

我想将Video label descriptionLabel category descriptionconfidence值存储到数据库(也许是MongoDB)中,然后在Noje.js应用程序中检索它。

我该怎么办?或者还有其他更好的方法吗?

没有什么可以阻止您这样做; 只要您的python程序和Node.js程序都同意如何存储数据,就可以轻松存储和检索简单字符串。 如果您事先知道需要检索的键,MongoDB作为键/值存储,将可以很好地工作。 如果您想基于某些条件来检索数据而又不知道确切的密钥,则SQLite之类的方法可能会更好。 Node.js和Python都具有运行良好的MongoDB / SQLite客户端。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM