Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何获取opencv中所有对象的所有像素?_Python_Opencv - Fatal编程技术网

Python 如何获取opencv中所有对象的所有像素?

Python 如何获取opencv中所有对象的所有像素?,python,opencv,Python,Opencv,我有一个单独对象的图像,它们有一种颜色 示例图像: 我想得到每个对象的所有像素。我使用Python和CV2。但我不知道怎么做 我想要得到的示例: object1:[(x1,y1),(x2,y2)…(xn1,yn1)],其中n1-计算object1中的所有像素 object2:[(x1,y1),(x2,y2)…(xn2,yn2)],其中n2-对object2中的所有像素进行计数 objectm:[(x1,y1),(x2,y2)…(xnm,ynm)],其中nm-计算objectm中的所有像素

我有一个单独对象的图像,它们有一种颜色

示例图像:

我想得到每个对象的所有像素。我使用Python和CV2。但我不知道怎么做

我想要得到的示例:

  • object1:[(x1,y1),(x2,y2)…(xn1,yn1)],其中n1-计算object1中的所有像素
  • object2:[(x1,y1),(x2,y2)…(xn2,yn2)],其中n2-对object2中的所有像素进行计数
  • objectm:[(x1,y1),(x2,y2)…(xnm,ynm)],其中nm-计算objectm中的所有像素

UPD:这可以通过cv2.connectedComponents()完成。看这个。考虑到img在“img”中是开放的,谢谢 您可以使用immg[i,j]返回蓝-红-绿的值

>>img[12,12]
[143,144,255] // this is what is returned [blue green red]
所以你可以用

rows = img.shape[0]
cols = img.shape[1]
for (i in range(0,rows)):
    for (j in range(0,cols)):
        bgr=img[i,j]
    #now use if condition and match brg values with color you wnana detect then append the pair i,j in the a list if the condition matcches 

考虑到img在“img”中是开放的 您可以使用immg[i,j]返回蓝-红-绿的值

>>img[12,12]
[143,144,255] // this is what is returned [blue green red]
所以你可以用

rows = img.shape[0]
cols = img.shape[1]
for (i in range(0,rows)):
    for (j in range(0,cols)):
        bgr=img[i,j]
    #now use if condition and match brg values with color you wnana detect then append the pair i,j in the a list if the condition matcches 

这不是我所期望的。因为您的算法没有将图像分割成单独的对象,所以这不是我所期望的。因为您的算法没有将图像分割为单独的对象,所以在给定的上下文中预期的输出是什么?请参阅在给定的上下文中预期的输出是什么?请参阅