Reputation: 101
I have an object of one color and I need to calculate the exact no of pixel occupied by object in captured image. How can I do this? I want to do this in Opencv. Please help...
Upvotes: 1
Views: 2124
Reputation: 52646
There are inbuilt functions for that in OpenCV.
1) Threshold the image so that object you needed is white and all other things are black.
Since you already have the object, i think you have done this step. If not, use Threshold functions in opencv
2) Find contours in the image
Use FindContours function for this.
3) Now find the area of the contour of the object you needed, which is the number of pixels occupied by it.
Use ContourArea function for this
Additional :
Not only just an area, there are a lot of other things you can find about an object like perimeter, centroid, mean value, orientation etc. Check this article to see them. Code is in Python, but you won't find any difficult to understand it.
Upvotes: 2