当前位置:网站首页>Depth Map-Based Object Detection
Depth Map-Based Object Detection
2022-08-05 12:17:00 【Cassiel_cx】
In the past few days, I have been in touch with the project of the car moving blocks. The visual algorithm is based on opencv. Although the method is simple, the effect is very nice. Today, I will make a record of the team's algorithm.
Method principle: frame difference detection, the depth map with the detection target and the background image without the target are compared to obtain the position of the target of interest.The specific steps are as follows,
1. Image reading
import cv2import numpy as npref_path = 'C:\Users/15989\Desktop\imgs/1.png'cur_path = 'C:\Users/15989\Desktop\imgs/201.png'cur_img = cv2.imread(cur_path, -1)ref_img = cv2.imread(ref_path, -1)Because the image is a 16-bit depth map, the image is normalized for easy viewing. The operation is as follows:
def norm(img):img = (img - img.min()) / (img.max() - img.min())img *= 255return imgRead the image as follows (background image/target image):

2. Make frame difference
diff_frame = cv2.absdiff(cur_img, ref_img)3. Select a region of interest
diff_frame_roi = diff_frame[200:, 200:540]4. Convert the image into a binary image
frame_bin = cv2.inRange(diff_frame_roi, 20, 100)5. Closure operation (expand first, then corrode) to eliminate small black holes
kernel = np.ones((3, 3), dtype=np.uint8)closing = cv2.morphologyEx(frame_bin, cv2.MORPH_CLOSE, kernel)6. Find the target contour
contours, _ = cv2.findContours(closing, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)7. Find the minimum circumscribed circle containing the contour and find the corresponding radius, filter the contour radius, calculate the minimum circumscribed rectangle of the contour that meets the requirements, filter the width and height of the circumscribed rectangle and their ratio, and select the appropriate sizeThe goal of the (parameter tuning is mainly concentrated in this link)
x_obj, y_obj = 0, 0w, h = 0, 0xl, yl = [], []wl, hl = [], []for cont in contours:(x, y), radius = cv2.minEnclosingCircle(cont)if radius > 13 and radius < 28:rect = cv2.minAreaRect(cont)x_obj, y_obj = rect[0]w, h = rect[1]if w/h > 1.5 or w/h < 0.5 or w*h < 500:continueelse:xl.append(x_obj)yl.append(y_obj)wl.append(w)hl.append(h)8. To get the final position of the target, since the picture is cropped in step 3, it is necessary to convert the coordinates obtained in the previous step into the coordinates of the original image and frame the target position in the picture
x_final = [xi + 200 for xi in xl]y_final = [yi + 200 for yi in yl]for x_f, y_f, w_f, h_f in zip(x_final, y_final, wl, hl):cv2.rectangle(cur_img, (int(x_f - w_f / 2), int(y_f - h_f / 2)), (int(x_f + w_f / 2), int(y_f + h_f / 2)), (0, 0, 0), thickness=2)
边栏推荐
- For high performance, large scale model training, this combination "career"
- KVM virtualization technology-NUMA technology and application
- Digital-intelligent supply chain system in the household appliance industry: efficiently integrate the supply chain and enhance the core competitiveness of household appliance enterprises
- solaris-oralce rac 安装
- ADC acquisition of CC2530
- Regular expressions in action
- 家用电器行业数智化供应链系统:高效整合供应链,提升家电企业核心竞争力
- 碘乙酰胺在Desthiobiotin-Iodoacetamide试剂中的作用?
- AVL树大总结
- Top 10 new features in Oracle Database 19c at a glance
猜你喜欢
随机推荐
ORACLE ASM提供的三种冗余方式
[Supply Chain·Case] What did the top ten retailers in the world do under the influence of the epidemic?
后台权限系统的设计以及主流的五种权限模型详解
Cesium.js 地形挖洞
Shang Silicon Valley-JUC
Methods in Reflect
内存问题难定位,那是因为你没用ASAN
Zhihu asks: Can China still achieve great national rejuvenation?
Face the summary - club resort - 6 years
我和 TiDB 的故事 | 学tidb半年,社区治好了我的精神内耗
797. Difference
MySQL之InnoDB和MyISAM区别
What is a buffer (buffer) and what is a cache (cache)
软件设计七大原则之开闭原则(Open-Closed Principle, OCP)
Small household appliance industry supply chain collaborative management system: help enterprises break through market competition and strengthen the rapid response capability of the supply chain
hello world、hello 计科人
solaris-磁盘管理
不是吧?还有人不会定位线上MySQL慢查询问题?
Oracle Database 19c 的10大新特性一览
COSCon'22城市/学校/机构出品人征集令









