Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

measuring height of color using pixel.

hello,

I am very new to opencv, I want to measure the height of the coloras in attached figure there is pipette with blood and i want to measure the level of blood in unit like mm. i try with contour but still not get any success to measure the volume. is there any suggestion or code please help me. i tryed also (http://answers.opencv.org/question/15992/measuring-the-dimensionheight-and-width-of-an-object/) 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.

click to hide/show revision 2
No.2 Revision

measuring height of color using pixel.

hello,

I am very new to opencv, I want to measure the height of the coloras in attached figure there is pipette with blood and i want to measure the level of blood in unit like mm. i try with contour but still not get any success to measure the volume. is there any suggestion or code please help me. i tryed also (http://answers.opencv.org/question/15992/measuring-the-dimensionheight-and-width-of-an-object/) but i am getting error. error.

`#include "opencv2/highgui/highgui.hpp"

include "opencv2/imgproc/imgproc.hpp"

include <opencv cxcore.h="">

include <iostream>

include <stdio.h>

include <stdlib.h>

"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;

std; int main(int argc, char** argv) { VideoCapture stream1(0); //0 is the id of video device.0 if you have only one camera.

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);

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> vector<vector<Point> > contours; vector<vec4i> hierarchy;

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;
}

waitKey(33);

} return 0; }

` i want to do measurement using usb camera. Thank you very much in advance for any possible help.

click to hide/show revision 3
No.3 Revision

measuring height of color using pixel.

hello,

I am very new to opencv, I want to measure the height of the coloras in attached figure there is pipette with blood and i want to measure the level of blood in unit like mm. i try with contour but still not get any success to measure the volume. is there any suggestion or code please help me. i tryed also (http://answers.opencv.org/question/15992/measuring-the-dimensionheight-and-width-of-an-object/) but i am getting error.

`#include #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.

click to hide/show revision 4
No.4 Revision

measuring height of color using pixel.

hello,

I am very new to opencv, I want to measure the height of the coloras in attached figure there is pipette with blood and i want to measure the level of blood in unit like mm. i try with contour but still not get any success to measure the volume. is there any suggestion or code please help me. i tryed also (http://answers.opencv.org/question/15992/measuring-the-dimensionheight-and-width-of-an-object/) 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.