版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第Unity实现识别图像中主体及其位置目录EasyDL图像分割介绍创建应用创建模型
EasyDL图像分割介绍
创建应用
1.进入百度AI开放平台打开控制台:
2.在左上角打开产品服务列表,找到EasyDL零门槛AI开放平台:
3.打开EasyDL图像:
4.在公有云部署-应用列表中创建一个应用:
5.创建完成后获取到AppID、APIKey、SecretKey:
创建模型
1.进入EasyGL图像分割:
2.创建模型:
3.创建数据集:
4.数据导入:
上传图片,图片的数量尽量多些
导入完成后查看并标注:
框选目标所在范围:
添加标签并为框选的目标设置标签:
设置完成后保存当前标注:
5.训练模型:(开始训练后需要等待一定时间)
6.发布模型:
发布完成后,拿到接口地址,来到Unity中,根据接口响应字段说明定义相应数据结构:
usingSystem;
[Serializable]
publicclassImageSegmentationResponse
///summary
///唯一的logid用于问题定位
////summary
publicintlog_id;
///summary
///标签数组结果
////summary
publicImageSegmentationResult[]results;
[Serializable]
publicclassImageSegmentationResult
///summary
///标签名称
////summary
publicstringname;
///summary
///置信度
////summary
publicstringscore;
///summary
///位置
////summary
publicLocationlocation;
///summary
///基于游程编码的字符串,编码内容为和原图宽高相同的布尔数组
///若数组值为0,代表原图此位置像素点不属于检测目标,若为1,代表原图此位置像素点属于检测目标
////summary
publicbool[]mask;
[Serializable]
publicclassLocation
///summary
///目标定位位置的长方形左上顶点的水平坐标
////summary
publicintleft;
///summary
///目标定位位置的长方形左上顶点的垂直坐标
////summary
publicinttop;
///summary
///目标定位位置的长方形的宽度
////summary
publicintwidth;
///summary
///目标定位位置的长方形的高度
////summary
publicintheight;
}
在任意一个模块下载C#SDK,例如在图像识别中下载,它是包含EasyDL的API内容的:
有了SDK后,放入Unity中的Plugins文件夹中,封装调用函数,只需要将检测图片的字节数据作为参数,其中appID、apiKey、secretKey是在上面创建应用时获取到的,url是发布模型时获取到的:
usingSystem;
usingUnityEngine;
///summary
///图像分割
////summary
publicclassImageSegmentation
privateconststringappID="";
privateconststringapiKey="";
privateconststringsecretKey="";
privateconststringurl="";
publicstaticImageSegmentationResult[]SendRequest(byte[]bytes)
varclient=newBaidu.Aip.EasyDL.EasyDL(appID,apiKey,secretKey);
varresponse=client.requestImage(url,bytes);
Debug.Log(response.ToString());
ImageSegmentationResponser=JsonUtility.FromJsonImageSegmentationResponse(response.ToString());
returnr.results;
catch(Exceptionerror)
Debug.LogError(error);
returnnull;
}
测试图片:
测试代码:
usingSystem.IO;
usingUnityEngine;
publicclassExample:MonoBehaviour
privatevoidStart()
ImageSegmentation.SendRequest(File.ReadAllBytes(Application.dataPath+"/1.jpg"));
返回结果:
拿到了定位数据后,接下来将其区域绘制出来,响应说明中解释(left,top)构成左上顶点,但是从返回值来看top为16,减去一个高度312的话,左下顶点的坐标已经是负数,这里姑且猜想它构成的是左下顶点:
首先创建一个Image来放置我们的测试图片,Canvas、Image大小也设为测试图片的大小640*359:
以下是测试脚本,将其挂载于Image测试:
usingSystem.IO;
usingUnityEngine;
publicclassExample:MonoBehaviour
privatevoidStart()
varresults=ImageSegmentation.SendRequest(File.ReadAllBytes(Application.dataPath+"/测试.jpg"));
for(inti=0;iresults.Length;i++)
varlocation=results[i].location;
LineRendererline=newGameObject("LineRenderer").AddComponentLineRenderer
line.positionCount=4;
line.loop=true;
Vector2leftTop=newVector2(location.left,location.top);
Vector2rightTop=newVector2(location.left+location.width,location.top);
Vector2leftBottom=newVector2(location.left,location.top+location.height);
Vector2rightBottom=newVector2(location.left+location.width,location.top+location.height);
RectTransformUtility.ScreenPointToWorldPointInRectangle(transformasRectTransform,leftTop,Camera.main,outVector3point1);
RectTransformUtility.ScreenPointToWorldPointInRectangle(transformasRectTransform,rightTop,Camera.main,outVector3point2);
RectTransformUtility.ScreenPointToWorldPointInRectangle(transformasRectTransform,rightBottom,Camera.main,outVector3point3);
RectTransformUtility.ScreenPointToWorldPointInRectangle(transformasRectTransform,leftBottom,Camera.main,outVector3point4);
line.SetPositio
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026汽车制造市场调研及发展技巧与投资回报预测报告
- 2026中国运动安全预警系统人工智能技术融合应用前景报告
- 2026中国涡流泵市场消费需求变化与用户行为调研报告
- 2026汽车零部件行业竞争格局调研与未来发展展望分析研究报告
- 新版教科版六年级上册科学(课件)第4单元 5机械钟摆
- 2026叶黄素酯原料产地资源分布与采购策略研究报告
- 2026中国消费品零售市场发展趋势及商业模式创新与投资前景预测研究报告
- 2026人工智能技术发展市场潜力分析探讨战略规划投资价值评估
- 2026能源监控设备行业市场应用分析评估发展策略研究
- 工业机器视觉技术与应用 课件 第五章-工业机器视觉目标检测与跟踪
- JG/T 478-2015建筑用穿墙防水对拉螺栓套具
- 肌间静脉血栓抗凝治疗
- GB/T 10810.5-2025眼镜镜片第5部分:表面耐磨试验方法
- 《复杂系统理论》课件
- 外出参加护理会议后汇报
- T-CTSS 3-2024 茶艺职业技能竞赛技术规程
- 2023年教育部高中技术课程标准
- 安华农险辽宁省(不含大连)中央财政玉米种植收入保险
- CJT 340-2016 绿化种植土壤
- 高标准农田改造提升建设项目投标方案(技术标)
- 光学成像技术1-课件
评论
0/150
提交评论