here I try to find contours after I turn the image to binary and remove lines
so my image looks like this when I send it in the function
then I start to find contours then I realized that there some contours that are a wrong one
this is the result
I cut every contour and save it in a file using this code
for row in removedImages:
objectDetectionImg, results = objectDetection(row)
for box in results:
Y, X, width, height = box
if ymin <= Y + (height / 2) <= ymax:
finalobject.append(box)
cv2.rectangle(objectDetectionImg, (int(X), int(Y)), (int(X + width), int(Y + height)), (0, 255, 0), 1)
symbol = objectDetectionImg[int(Y):int(Y + height), int(X):int(X + width)]
cv2.imwrite((out_path + str(i) + ".bmp"), symbol)
i += 1
objectDetectionImages.append(objectDetectionImg)
and this is the object detection function
def objectDetection(LineRemoved):
contours = find_contours(LineRemoved, 0.8)
results = []
for c in contours:
ll, ur = np.min(c, 0), np.max(c, 0) # getting the two points
wh = ur - ll # getting the width and the height
(x, y, w, h) = ll[0], ll[1], wh[1], wh[0]
results.append((x, y, w, h))
return LineRemoved, results
I am sorry if there anything that explained badly
ask me if you need more information
thanks in advance
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…