开通服务

环境

pip install --upgrade azure-cognitiveservices-vision-computervision
pip install pillow

subscription_key = “”
endpoint = “”
这两个是你需要的,在注册中获得.另外这个服务是免费的,每月限定次数,每次限定并发

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 CognitiveServicesCredentialsfrom array import array
import os
from PIL import Image
import sys
import timesubscription_key = "xxxxx"
endpoint = "xxxxx"computervision_client = ComputerVisionClient(endpoint, CognitiveServicesCredentials(subscription_key))
#==============================  描述一副图(带置信度)  ===================================
local_image = open("fun.jpeg", "rb")
description_result = computervision_client.describe_image_in_stream(local_image)if (len(description_result.captions) == 0):print("No description detected.")
else:for caption in description_result.captions:print(caption)print("'{}' with confidence {:.2f}%".format(caption.text, caption.confidence * 100))

结果: a woman holding a book’ with confidence 51.00%

#==============================  位置检测 ===================================
local_image_objects = open('catjpeg.jpeg', "rb")
detect_objects_results_local = computervision_client.detect_objects_in_stream(local_image_objects)if len(detect_objects_results_local.objects) == 0:print("No objects detected.")
else:for object in detect_objects_results_local.objects:print(object)print("object at location {}, {}, {}, {}".format( \object.rectangle.x, object.rectangle.x + object.rectangle.w, \object.rectangle.y, object.rectangle.y + object.rectangle.h))

结果: object at location 456, 748, 22, 576
object at location 720, 997, 2, 572

#==============================  分类  ===================================
local_image = open('catjpeg.jpeg', "rb")
# Select visual feature type(s)
local_image_features = ["categories"]
# Call API
categorize_results_local = computervision_client.analyze_image_in_stream(local_image, local_image_features)# Print category results with confidence score
print("Categories from local image: ")
if (len(categorize_results_local.categories) == 0):print("No categories detected.")
else:for category in categorize_results_local.categories:print("'{}' with confidence {:.2f}%".format(category.name, category.score * 100))

结果: animal_cat’ with confidence 96.88%

#==============================  图中所有可能存在的东西  ===================================
local_image = open('catjpeg.jpeg', "rb")
# Call API local image
tags_result_local = computervision_client.tag_image_in_stream(local_image)# Print results with confidence score
print("Tags in the local image: ")
if (len(tags_result_local.tags) == 0):print("No tags detected.")
else:for tag in tags_result_local.tags:print("'{}' with confidence {:.2f}%".format(tag.name, tag.confidence * 100))

结果:
‘person’ with confidence 99.83%
‘tree’ with confidence 99.27%
‘clothing’ with confidence 99.14%
‘human face’ with confidence 97.90%
‘woman’ with confidence 93.78%
‘outdoor’ with confidence 92.40%
‘lady’ with confidence 92.21%
‘long hair’ with confidence 91.87%
‘photo shoot’ with confidence 90.29%
‘fashion accessory’ with confidence 89.75%
‘female person’ with confidence 89.10%
‘waist’ with confidence 87.91%
‘day dress’ with confidence 85.61%
‘holding’ with confidence 73.37%
‘girl’ with confidence 69.34%
‘young’ with confidence 63.56%
‘wearing’ with confidence 55.63%
‘dress’ with confidence 55.21%

#==============================  人脸检测  ===================================
local_image = open('test.jpeg', "rb")
local_image_features = ["faces"]
detect_faces_results_local = computervision_client.analyze_image_in_stream(local_image, local_image_features)print("Faces in the local image: ")
if (len(detect_faces_results_local.faces) == 0):print("No faces detected.")
else:for face in detect_faces_results_local.faces:print("'{}' of age {} at location {}, {}, {}, {}".format(face.gender, face.age, \face.face_rectangle.left, face.face_rectangle.top, \face.face_rectangle.left + face.face_rectangle.width, \face.face_rectangle.top + face.face_rectangle.height))

结果: Female of age 23 at location 163, 97, 263, 197

#==================== 羞羞 检测 =================================
local_image = open('fun.jpeg', "rb")
local_image_features = ["adult"]
detect_adult_results_local = computervision_client.analyze_image_in_stream(local_image, local_image_features)print("Analyzing local image for adult or racy content ... ")
print("Is adult content: {} with confidence {:.2f}".format(detect_adult_results_local .adult.is_adult_content, detect_adult_results_local .adult.adult_score * 100))
print("Has racy content: {} with confidence {:.2f}".format(detect_adult_results_local .adult.is_racy_content, detect_adult_results_local .adult.racy_score * 100))

结果:
Is adult content: False with confidence 0.29
Has racy content: False with confidence 0.47

#==================== 不同类型边界框检测 =================================
local_image_objects = open('catjpeg.jpeg', "rb")
# Call API with local image
detect_objects_results_local = computervision_client.detect_objects_in_stream(local_image_objects)# Print results of detection with bounding boxes
print("Detecting objects in local image:")
if len(detect_objects_results_local.objects) == 0:print("No objects detected.")
else:for object in detect_objects_results_local.objects:print("object at location {}, {}, {}, {}".format( \object.rectangle.x, object.rectangle.x + object.rectangle.w, \object.rectangle.y, object.rectangle.y + object.rectangle.h))

object at location 456, 748, 22, 576
object at location 720, 997, 2, 572

Azure 微软|人脸检测|边界框检测|物体分类检测|WEB_API|PYTHON相关推荐

  1. 李沐动手学深度学习V2-目标检测边界框

    一. 目标检测边界框 加载本节使用的示例图像,可以看到图像左边是一只狗,右边是一只猫,它们是这张图像里的两个主要目标,如下图所示. import torch import d2l import d2l ...

  2. 深度学习(目标跟踪和目标检测)--边界框bbox坐标转换(任意格式【list,numpy,tensor】、任意维度【向量、一维矩阵、二维矩阵】)

    作者提示:可能存在错误,在我的电脑上可以运行: 写程序过程中发现不同的人写的边界框转换程序不一样, 有的只能转换numpy矩阵, 有的只能是转换tensor矩阵, 我就尝试着写了一个可以转换任何维度的 ...

  3. 【自动驾驶】鸽了很久的小物体目标检测代码【小物体目标检测】

    鸽了很久的小物体目标检测代码 https://github.com/LT1st/SmallObstacleDetection/tree/main/code#readme Pytorch: Small ...

  4. 目标检测--边界框(bounding box)解析

    用于学习参考,源自:https://blog.csdn.net/zijin0802034/article/details/77685438/

  5. ECCV18 Oral | CornerNet目标检测开启预测“边界框”到预测“点对”的新思路

    性能超过所有one-stage类型目标检测算法,训练和测试代码均已开源. 本文来自ECCV2018 Oral论文<CornerNet: Detecting Objects as Paired K ...

  6. 为什么vs会输出一个框作为结果_检测与分类专辑 | 对精准目标检测的含不确定性的边界框回归...

    摘要 大型目标检测数据集(如MS-COCO) 试着尽可能地将边界框框的非常清晰,但是在标记边框时会存在歧义.在本文中,提出了一种新的边界框回归损失学习边界框的移动及位置方差,此方法在不增加计算量的基础 ...

  7. 计算机视觉(一)—— 目标检测和边界框

    文章目录 1. 什么是目标检测 2. 目标检测大致思路 2.1 边界框 2.2 合理的边界框? 2.2.1 某一种锚框的生成方法 2.2.1.1 方法描述 2.2.1.2 代码 2.2.2 锚框优劣的 ...

  8. 6--目标检测和边界框和锚框

    很多时候图像里有多个目标,不仅想知道它们的类别,还想得到它们在图像中的具体位置. 在计算机视觉里,这类任务称为目标检测(object detection). 6.1 边界框  边界框(bounding ...

  9. 单目摄像头检测输出 3D 边界框

    单目摄像头检测输出 3D 边界框 单纯的 2D 检测框无法在 3D 空间去做规划控制,单目图像估计 3D 检测框也是自动驾驶研发的一个课题,百度 Apollo 发布 2.5 / 3.0 版本特意提到这 ...

最新文章

  1. CPU的自动调度矩阵乘法
  2. golang float浮点型精度丢失问题解决办法:使用decimal包;float与int的相互转换
  3. netbeans项目缺少服务器,Netbeans,添加Glassfish服务器“不存在”
  4. 程序员诗词大赛开始了,你看过吗?
  5. 01_Redis基础
  6. 【ICLR2021必读】 【自监督学习】 【Transformer】相关论文
  7. JSP指令、动作和对象
  8. 《数据库系统基础教程》概念
  9. Android得到位图方式
  10. 如何正确的制定目标?(只需4步)
  11. 【读后感1】读《我是一只it小小鸟》有感
  12. 黑马培训---分享点干货二 IOS面试非技术性问题
  13. 解决webpack打包报错: Cannot find module '@webassemblyjs/wasm-parser'
  14. Android图库选择图片
  15. WINCE上网本才是正道——关于目前ARM+CE的上网本的文章汇编
  16. 计蒜客 因数最多的数
  17. 开放式式商业模式_开放式和封闭式耳机之间有什么区别,我应该得到什么?
  18. 专业项目管理软件统御项目管理系统V7.0(oKit)试用感受
  19. 【干货】怎么将阿里云ECS的数据下载到本地
  20. JSHOP2算例介绍:blocksworld问题

热门文章

  1. Day2.上海地铁网络图路径显示
  2. 在亚洲市场进行夜间交易: 如何保持盈利
  3. vos对接得伯乐GSM网关
  4. 算法竞赛---day5(方格分割)
  5. 科学计算机解多元方程组,南京大学计算机科学与技术系 数值计算方法(第3章)3 向量和矩阵的范数 病态方程组 解线性方程组的迭代法.ppt...
  6. data:text/html;c,html image -- data:image/png;base64
  7. 音视频通话的方案记录
  8. 三菱modbusRTU通讯实例_实例 | 威纶触摸屏与三菱D700变频器通讯
  9. 人人php 路由,关于人人分销/人人商城的二次开发路由解析
  10. 宝钢洽购沙钢 钢铁航母隐现