我正在尝试从关系数据库中检测所有矩形。但是我的脚本没有检测到一些盒子。请帮我做到这一点。谢谢你。
图片:

我的代码:
#!/usr/bin/python
import cv2
import numpy as np
im = cv2.imread("table.png")
image = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(image,0,255,cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
edge = cv2.Canny(thresh,30,200)
cont = cv2.findContours(edge,cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)[0]
for j,i in enumerate(cont):
x,y,w,h = cv2.boundingRect(i)
if (w*h>900):
cv2.drawContours(image,[i],0,(0,0,255),3)
cv2.imshow("Image",image)
cv2.waitKey(0)
Run Code Online (Sandbox Code Playgroud)
输出: