简体   繁体   English

图中未显示边界框

[英]Bounding box is not shown in plot

I tried to plot my image with the center point and the bounding-box.我试图用中心点和边界框绘制我的图像。 In the variable rect are the information for heigh, weidth, angle and center point, so I assume that the contours and everything is found correctly.在变量rect是高度、宽度、角度和中心点的信息,所以我假设轮廓和一切都被正确找到。 But why is it not shown in the plot?但为什么它没有显示在图中?

hierachy, img_threshold_32bit = cv2.threshold(img_hr, 100, 255, cv2.THRESH_BINARY)
img_8bit = np.array(img_threshold_32bit,dtype=np.uint8)    
contours,_ = cv2.findContours(img_8bit, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)    
cv2.drawContours(img_8bit, contours, -1, (0, 255, 0), 2, cv2.LINE_AA)

for cnt in contours:         
      rect = cv2.minAreaRect(cnt)
      box = cv2.boxPoints(rect)
      box = np.int0(box)
      cv2.drawContours(img_8bit,[box],0,(0,0,255),2)
      cv2.circle(img_8bit,(int(rect[0][0]),int(rect[0][1])),5,(255,0,0),-1)

plt.imshow(img_8bit)

Thanks for your help谢谢你的帮助

You are using a 3 channel image, so instead of plt.imshow() use您使用的是 3 通道图像,因此不要使用plt.imshow()

cv2.imshow("image name",img_8bit)
cv2.waitKey(0)
cv2.destroyAllWindows()

This worked for me as well.这对我也有效。 Hope this solves your problem.希望这能解决您的问题。

Since the image was binary, first I need to convert it back to 3 channels.由于图像是二进制的,首先我需要将其转换回 3 个通道。 After this the bounding box is shown correctly in the image.在此之后,边界框在图像中正确显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM