在室外条件下使用Intel Sealsense D415的机器人的线路。

发布于 2025-02-07 01:13:02 字数 1162 浏览 3 评论 0原文

我正在努力使用OpenCV跟随机器人制作线路,并正在使用NVIDIA REALSENSE D415深度摄像头进行图像捕获。我正在使用CV2.FindContours,并将最大轮廓作为线路,然后在该线路上进行工作。问题在于检测主线,代码还检测到随机轮廓,例如当我在地面上捕获空空间时,它将整个框架视为一个轮廓。它还将随机对象作为轮廓捡起。有没有办法仅检测黑线?还有其他物体作为轮廓吗?

代码:

cap = cv2.VideoCapture(2) 
ret,frame = cap.read()
frame = frame[0:800,0:1800]
value = 80 #whatever value you want to add
cv2.add(frame[:,:,2], value, frame[:,:,2])
img = cv2.cvtColor(frame, cv2.COLOR_HSV2BGR)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = cv2.GaussianBlur(img,(5,5),0)
_,threshold = cv2.threshold(img,60,255,cv2.THRESH_BINARY_INV) 
mask = cv2.erode(threshold, None, iterations=2)
mask = cv2.dilate(mask, None, iterations=2)
contours, hierarchy = 
cv2.findContours(mask.copy(),1,cv2.CHAIN_APPROX_NONE)
max_c = max(contours, key=cv2.contourArea)
cv2.drawContours(img, max_c, -1, (0,255,0), 3)

” png“ alt =”处理使用给定代码上方中的给定代码后的摄像机图像>

带有对象的图像

I am working on making a line following robot using Opencv and am using nvidia realsense d415 depth camera for image capturing.I am using cv2.findcontours and taking the max contour as the line and then working on that. the problem is along with detecting the main line , the code is also detecting random contours, like when I capture empty space on ground, it considers the whole frame as one contour. It is also picking up random objects as contour. Is there a way to detect just the black line? and no other object as contour?

Code:

cap = cv2.VideoCapture(2) 
ret,frame = cap.read()
frame = frame[0:800,0:1800]
value = 80 #whatever value you want to add
cv2.add(frame[:,:,2], value, frame[:,:,2])
img = cv2.cvtColor(frame, cv2.COLOR_HSV2BGR)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = cv2.GaussianBlur(img,(5,5),0)
_,threshold = cv2.threshold(img,60,255,cv2.THRESH_BINARY_INV) 
mask = cv2.erode(threshold, None, iterations=2)
mask = cv2.dilate(mask, None, iterations=2)
contours, hierarchy = 
cv2.findContours(mask.copy(),1,cv2.CHAIN_APPROX_NONE)
max_c = max(contours, key=cv2.contourArea)
cv2.drawContours(img, max_c, -1, (0,255,0), 3)

code

camera image after processing using given code in above img

Image with object

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文