使用微软 azure-cognitiveservices 识别实验操作柜内仪表数据(一)

   日期:2021-03-31     浏览:162    评论:0    
核心提示:文章目录前言[1个简单Demo]使用计算机视觉客户端,获取该物体的描述1.安装客户端库2.创建Python应用程序3.实例化4.获取description_result总结前言场景:P2实验室某安全区域有一环境检测仪表,具备检测空间内温度、湿度、噪声等环境安全指标。如何通过无线(不与仪表建立直接物理连接)方式准确获取仪表实时数据,并接入中控系统呢?通过结合高清摄像头与 azure-cognitiveservices 的方案值得考虑。提示:以下是本篇文章正文内容,下面案例可供参考[1个简

文章目录

  • 前言
  • [1个简单Demo]使用计算机视觉客户端,获取该物体的描述
    • 1.安装客户端库
    • 2.创建Python应用程序
    • 3.实例化
    • 4.获取description_result
    • 5.完整代码

前言

场景:P2实验室某安全区域有一环境检测仪表,具备检测空间内温度、湿度、噪声等环境安全指标。
如何通过无线(不与仪表建立直接物理连接)方式准确获取仪表实时数据,并接入中控系统呢?通过结合高清摄像头与 azure-cognitiveservices 的方案值得考虑。

提示:以下是本篇文章正文内容,下面案例可供参考

[1个简单Demo]使用计算机视觉客户端,获取该物体的描述

1.安装客户端库

代码如下:

pip install –upgrade azure-cognitiveservices-vision-computervision

pip install pillow

2.创建Python应用程序

代码如下:

from azure.cognitiveservices.vision.computervision import ComputerVisionClient
from azure.cognitiveservices.vision.computervision.models import OperationStatusCodes
from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes
from msrest.authentication import CognitiveServicesCredentials

from array import array
import os
from PIL import Image
import sys
import time

subscription_key =”PASTE_YOUR_COMPUTER_VISION_SUBSCRIPTION_KEY_HERE”
endpoint = “PASTE_YOUR_COMPUTER_VISION_ENDPOINT_HERE”

3.实例化

代码如下:

computervision_client = ComputerVisionClient(endpoint, CognitiveServicesCredentials(subscription_key))

local_image_path =./sensor/sensor.jpg”

local_image = open(local_image_path, “rb”)

4.获取description_result

代码如下:

description_result = computervision_client.describe_image_in_stream(local_image)

print(“Description of local image:)
if (len(description_result.captions) == 0):
print(“No description detected.)
else:
for caption in description_result.captions:
print(“‘{ }’ with confidence { :.2f}%.format(caption.text, caption.confidence * 100))

=========== result ===============

===== Describe an Image – local =====
Description of local image:
‘a rectangular sign with blue text’ with confidence 31.88%

5.完整代码

代码如下:

from logging import exception

from azure.cognitiveservices.vision.computervision import ComputerVisionClient
from msrest.authentication import CognitiveServicesCredentials

subscription_key =”PASTE_YOUR_COMPUTER_VISION_SUBSCRIPTION_KEY_HERE”
endpoint = “PASTE_YOUR_COMPUTER_VISION_ENDPOINT_HERE”
local_image_path =./sensor/sensor.jpg”

 

def main():
try:
print(===== Describe an Sensor-Screenshot =====)
computervision_client = ComputerVisionClient(endpoint, CognitiveServicesCredentials(subscription_key))
# Open local image file
local_image = open(local_image_path, “rb”)

# Call API
description_result = computervision_client.describe_image_in_stream(local_image)

# Get the captions (descriptions) from the response, with confidence level
print(“Description of local image:)
if (len(description_result.captions) == 0):
print(“No description detected.)
else:
for caption in description_result.captions:
print(“‘{ }’ with confidence { :.2f}%.format(caption.text, caption.confidence * 100))

except exception as re:
print(re)

 

if __name__ == ‘__main__’:
main()
 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
更多>相关资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服