ValueError:太多值无法解包-OpenCV Python HoughLines

时间:2019-07-05 19:10:13

标签: python opencv hough-transform

由于来自OpenCV的HoughLine,我试图从图像中检测到的一行中获取rho和theta。

lines = cv.HoughLinesP(edges, 1, np.pi/180, hThreshold, maxLineGap=lineGap)
if lines is not None:
    for line in lines:
       rho, theta = line[0]

但是我在最后一行收到此错误。

  

ValueError:太多值无法解包

您知道如何解决此问题吗?还是获取rho和theta值的另一种方法?

PS:我安装了带有pip3的opencv-python和install opencv-python --user

1 个答案:

答案 0 :(得分:0)

上面的代码中的

DWORD flags = 0; // <-- want either format LPVOID pointerToMetaData = XWF_GetMetadataEx(hItem, &flags); if (pointerToMetaData) { if ((flags & 0xFF000000) == 0) // is the buffer usable? { if (flags & 1) { char *HtmlAsciiMetaData = (char*) pointerToMetaData; // use HtmlAsciiMetaData as needed... } else { wchar_t *Utf16PlainTextMetaData = (wchar_t*) pointerToMetaData; // use Utf16PlainTextMetaData as needed... } } XWF_ReleaseMem(pointerToMetaData); } 是一个包含4个值的列表。这就是为什么,您遇到了错误。您正在做的是尝试使用line[0](即

)检测行
Probabilistic Hough lines

正确的代码:

lines = cv2.HoughLinesP(binarized image, ro accuracy, theta accurancy, threshold, minimum line length, max line gap)

但是,您要做的是使用lines = cv.HoughLinesP(edges, 1, np.pi/180, hThreshold, maxLineGap=lineGap) for line in lines: x1, y1, x2, y2 = line[0] 进行线路检测。因此,将您的代码从Hough lines更改为

lines = cv.HoughLinesP(edges, 1, np.pi/180, hThreshold, maxLineGap=lineGap)
相关问题