I have image with separate objects, which have one color.
example image:
I want to get all the pixels from each object. I use Python and CV2. But I do not know how to do it.
example that i want to get:
UPD: This can be done with cv2.connectedComponents(). See this connected component labeling in python . Thanks beaker
considering that the img is open in 'img' you can use immg[i,j] to return values of blue red green eg
>>img[12,12]
[143,144,255] // this is what is returned [blue green red]
so you can use something like
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.