簡體   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