如何将检测到的连接组件一个接一个地连接或粘贴?

我想使用从文本图像中提取的连接组件来创建256 * 256图像。 想法是并排(随机)串联或显示或粘贴CC,直到获得256 * 256图像,这意味着sum_height_CC = 256和sum_widh_CC = 256。给出了检测CC的代码

def process(gray_img):

        gauss_img = cv2.GaussianBlur(gray_img,(5,5),0)  

        kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3))

        th4 = cv2.morphologyEx(gauss_img,cv2.MORPH_GRADIENT,kernel)
        ret3,th3 = cv2.threshold(th4,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
        morph_kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(8,8))
        connected = cv2.morphologyEx(th3,cv2.MORPH_CLOSE,morph_kernel)
        output = cv2.connectedComponentsWithStats(connected,connectivity=8)
        for i in range(output[0]):
            if output[2][i][4] >= 300 and output[2][i][4] <= 10000:
                CC=cv2.rectangle(th3,(output[2][i][0],output[2][i][1]),(output[2][i][0] + output[2][i][2],output[2][i][1] + output[2][i][3]),(255,255),2)

#♣======================== get all the detected CC as images ======================================

#                res = gray_img[output[2][i][1]:output[2][i][1] + output[2][i][3],output[2][i][0]:output[2][i][0] + output[2][i][2]]
#                cv2.imwrite(r"component%s.jpg" %str(i),res)

#♣===================================== show results ==============================================     
        cv2.imshow("detection",CC)
        cv2.imshow("original",gray_img)
        cv2.waitKey(0)
        cv2.destroyAllWindows()

感谢您的帮助。

cheungdmin19791004 回答:如何将检测到的连接组件一个接一个地连接或粘贴?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2804470.html

大家都在问