measuring height of color using pixel. [closed]
hello,
I am very new to opencv, I want to measure the height of the coloris there any suggestion or code please help me. i tryed also (http://answers.opencv.org/question/15...) but i am getting error.
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv/cxcore.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
VideoCapture stream1(0); //0 is the id of video device.0 if you have only one camera.
stream1.set(CV_CAP_PROP_FRAME_WIDTH, 640);
stream1.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
int thresh = 100; int max_thresh = 255; RNG rng(12345);
if (!stream1.isOpened()) {
//check if video device has been initialised
cout << "cannot open camera";
}
//unconditional loop
while (true) {
Mat cameraFrame;
Mat src_gray;
Mat threshold_output;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
cvtColor( cameraFrame,src_gray, CV_BGR2GRAY ); // produces out2, a one-channel image (CV_8UC1)
blur( src_gray, src_gray, Size(5,5) );
threshold( src_gray, threshold_output, 150, 200, CV_THRESH_BINARY_INV);
findContours( threshold_output, contours, hierarchy,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
/// Find the rotated rectangles
vector<RotatedRect> minRect( contours.size() );
for( int i = 0; i < contours.size(); i++ )
{ minRect[i] = minAreaRect( Mat(contours[i]) ); }
/// Draw contours + rotated rects + ellipses
Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 );
for( int i = 0; i < contours.size(); i++ )
{ Scalar color = Scalar( rng.uniform(0,0), rng.uniform(0,0), rng.uniform(250,250) ); // contour drawContours( drawing, contours, i, color, 1, 8, vector<vec4i>(), 0, Point() ); // rotated rectangle
Point2f rect_points[4]; minRect[i].points( rect_points );
for(int j = 0; j < 4; j++ )
line( cameraFrame, rect_points[j], rect_points[(j+1)%4], color, 1, 8 );
}
if (stream1.read(cameraFrame))
{
namedWindow("cam", 1);
imshow("cam", cameraFrame);
}
waitKey(33);
}
return 0;
}
` i want to do measurement using usb camera. Thank you very much in advance for any possible help.
May you can use surface area if you camera is always at same position relative to object.
I find that black surface is 8205 pixels (you must have this value [http://docs.opencv.org/3.0-beta/modul...]) . After you can make a table surface<-> height
Could you be a bit more specific? What does happen? What should happen?
Thank you for your suggestions, my camera position is fixed, and I have to detect 3 colors at a same time. and i have to measure its level means width.
In your image you haven't got any background so I think you can work with histogram. Histogram integration around your three color will give you region surface. An another idea is to use PCA to find good axis to convert your color image in grayscale instead of cvtColor
Hi,Why not use blob or find bounding?????