类型错误:标签不是numpy数组,也不是s

2024-09-27 04:25:26 发布

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

从cv2开始,我想要的是给对象一个种子,就像在某个坐标窗口中那样,让他连接所有可能在初始坐标框之外但与之接触的像素。 我从一些小测试开始,以了解连接的组件:

im=cv2.imread('test.png', 0)
ret, thresh = cv2.threshold(im, 254, 255, cv2.THRESH_BINARY)
output = cv2.connectedComponentsWithStats(thresh, 4, cv2.CV_32S)

那么

^{pr2}$

这两个输出数组,到目前为止还不错,然后我想看到实际的输出图像,它引用了文档https://docs.opencv.org/3.0-beta/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#connectedcomponentsconnectedComponentsWithStats(InputArray image, OutputArray labels, OutputArray stats, OutputArray centroids, int connectivity=8, int ltype=CV_32S)和{},所以我将上面共享的小代码中的最后一行改为:

output = cv2.connectedComponents(thresh,"out_test.png" ,4, cv2.CV_32S)

这给了我这个问题中的错误。我也试着:

cv2.imwrite(dest_dir+"out_test.png", output)

得到了这个错误:

TypeError: img is not a numerical tuple

当我不想计算blob(对象)、它们的大小或其他任何我只想让它们从我给出的原始感兴趣的区域增长时,我如何实际地可视化输出呢。在


Tags: 对象testoutputpng错误组件像素out
2条回答

如果您想让白色斑点变大,可以使用Morphological Transformations

在使用之前一定要了解函数的作用

cv2.connectedComponents

Help on built-in function connectedComponents:

connectedComponents(...)
    connectedComponents(image[, labels[, connectivity[, ltype]]]) -> retval, labels
    .   @overload
    .   
    .   @param image the 8-bit single-channel image to be labeled
    .   @param labels destination labeled image
    .   @param connectivity 8 or 4 for 8-way or 4-way connectivity respectively
    .   @param ltype output image label type. Currently CV_32S and CV_16U are supported

@ausk答案应该对你有用

import cv2

在终端中打开python之后

示例

help(cv2.connectedComponents)

希望这有帮助

^{pr2}$
Help on built-in function connectedComponents:

connectedComponents(...)
    connectedComponents(image[, labels[, connectivity[, ltype]]]) -> retval, labels
    .   @overload
    .
    .   @param image the 8-bit single-channel image to be labeled
    .   @param labels destination labeled image
    .   @param connectivity 8 or 4 for 8-way or 4-way connectivity respectively
    .   @param ltype output image label type. Currently CV_32S and CV_16U are supported.

^{pr2}$

相关问题 更多 >

    热门问题