如何提高图像的直线检测?

2024-09-19 23:42:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要帮助找出cv2.HoughLinesP参数,以获得满意的线路检测结果。你知道吗

输入图像如下:

input image

其中一个输出图像如下:

output image

我已经通过了各种rho,θ,阈值,minLineLength,maxLineGap值,但没有一个结果是令人满意的。你知道吗

for rho in range(1,100,10):
    for thetadiv in range(10,400,50):
        for threshold in range(1,50,5):
            for mL in range(5,100,5):
                for mG in range(1,5):
                    imout,tag=dump_pline(im1inv, rho, thetadiv, threshold, mL, mG)
                    cv2.imwrite(path+"\\"+tag+".jpg",mask)


def dump_pline(img, rho=1, thetadiv=100, threshold=10, mL=10, mG=5):
    im=np.copy(img)
    lines=cv2.HoughLinesP(im, rho=rho, theta=np.pi/thetadiv, threshold=threshold, minLineLength=mL, maxLineGap=mG)
    tag="rho-"+str(rho)+" thetadiv-"+str(thetadiv)+" threshold-"+str(threshold)+" mL-"+str(mL)+" mG-"+str(mG)
    print(tag)
    mask=np.zeros(im.shape[:2],dtype='uint8')
    mask.fill(255)
    a,b,c=lines.shape
    for i in range(a):
        cv2.line(mask,(lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3]),(0,255,0), 1, cv2.LINE_AA)
    mask[mask<255]=0
    return mask, tag

我得到的大部分图像都很暗,与输入图像一点都不相似。你知道吗

我该怎么解决这个问题?你知道吗


Tags: in图像forthresholdtagrangemaskcv2