Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
155 views
in Technique[技术] by (71.8m points)

python - image find_contours not perfect

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 LineRemoved

then I start to find contours then I realized that there some contours that are a wrong one this is the result

enter image description here

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...