深度学习-目标检测
應用背景:在AI視覺領域,許多高精度測量場景,需要搭配傳統視覺算法,才會有更好的使用效果。例如,本項目測量被檢目標的長度,需要兩個步驟 ①框選識別被檢目標;②對被檢目標進行分析測量。
程序功能:本程序功能,通過深度學習算法框選出被檢目標后,可獲取到備選框坐標,根據坐標值裁切目標區域圖像,方便進一步分析。
備注:深度學習Infer預測及模型本篇并未展示。
"""
功能:識別兩個被檢目標,并裁切目標區域圖像
"""from infer import getRes,buildDetector
import cv2
import timecover_path = "D:/Users/xuyf2/Desktop/lego_jier/cp1622130202.jpg"
im1 = cv2.imread(cover_path)
im2 = cv2.resize(im1,(640,480),)# 通過目標檢測,裁剪出檢測到的圖像
detector = buildDetector(model_dir='model/lego_jier_V1.01')
res, img = getRes(image_file=im2, detector=detector)for k, v in res.items():# 打印檢測到目標個數print(len(v))# left_point 左側框坐標x1_left_top = v[0][2]y1_left_top = v[0][3]x1_right_bottom = v[0][4]y1_right_bottom = v[0][5]# right_point 右側框坐標x2_left_top = v[1][2]y2_left_top = v[1][3]x2_right_bottom = v[1][4]y2_right_bottom = v[1][5]# 打印坐標點print('(x1,y1)-top',int(x1_left_top),int(y1_left_top))print('(x1,y1)-bottom',int(x1_right_bottom),int(y1_right_bottom))print('(x2,y2)-top',int(x2_left_top),int(y2_left_top))print('(x2,y2)-bottom',int(x2_right_bottom),int(y2_right_bottom))# 圖片存儲
t = time.time()
img_str = 'cp' + str(int(t))
crop1 = im2[int(y1_left_top):int(y1_right_bottom), int(x1_left_top):int(x1_right_bottom)]
cv2.imwrite("D:/Users/xuyf2/Desktop/lego_jier/crop1/" + '1' + img_str + ".jpg", crop1)
crop2 = im2[int(y2_left_top):int(y2_right_bottom), int(x2_left_top):int(x2_right_bottom)]
cv2.imwrite("D:/Users/xuyf2/Desktop/lego_jier/crop2/" + '2' + img_str + ".jpg", crop2)
?效果展示:
總結
 
                            
                        - 上一篇: 想翻译美村每天刊登的关于中国的新闻,请问
- 下一篇: 看夕阳西下一句是什么啊?
