ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If you haven't already, I'd suggest looking at NumPy for manipulating your OpenCV images in Python. If you load your images as CvMat objects instead of IplImages then you can manipulate them as NumPy objects without copying the data.

NumPy takes a while to get your head around, but once you do you can use techniques such as the ones given here to achieve what you want.

Based on that, running this program

#! /usr/bin/env python

import cv
import numpy

cvImg = cv.LoadImageM( "testImage.png",     # Must use LoadImageM
    iscolor=cv.CV_LOAD_IMAGE_GRAYSCALE )
npImg = numpy.asarray( cvImg )  # No copying takes place

coordList = numpy.argwhere( npImg == 255 )
numWhitePoints = len( coordList )

print coordList
print "Found {0} points".format( numWhitePoints )

on your image should output like this

[[ 97 318]
 [ 97 322]
 [ 97 323]
   .. ..
   .. ..
 [141 200]
 [146 189]
 [153 178]]
Found 216 points