xcode - OpenCV C++ Mat to Integer -



xcode - OpenCV C++ Mat to Integer -

i'm pretty new opencv, bear me. i'm running mac mini osx 10.8. have programme recognizes colors , displays them in binary image (black , white). however, want store number of white pixels integer (or float, etc.) compare other number of pixels. how can this? here current code-

#include <iostream> #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/core/core.hpp" using namespace cv; using namespace std; int main( int argc, char** argv ) { videocapture cap(0); //capture video webcam if ( !cap.isopened() ) // if not success, exit programme { cout << "cannot open web cam" << endl; homecoming -1; } namedwindow("hsvleftred", cv_window_autosize); namedwindow("hsvleftgreen", cv_window_autosize); while (true) { mat image; cap.read(image); mat hsv; mat leftgreen; mat leftred; //left cropping mat leftimg = image(rect(0, 0, 640, 720)); //left reddish detection cvtcolor(leftimg,hsv,cv_bgr2hsv); inrange(hsv,scalar(0,0,150),scalar(0,0,255), leftgreen); //imshow("hsvleftred", leftgreen); //print pixel type //left greenish detection cvtcolor(leftimg,hsv,cv_bgr2hsv); inrange(hsv,scalar(still need find proper min values),scalar(still need find proper max values), leftgreen); //imshow("hsvleftgreen", leftgreen); //compare pixel types } homecoming 0; }

thanks in advance!

to count non-zero pixels, opencv has function cv::countnonzero. takes input image, number of non-zero pixels, want calculate , output number of non-zero pixels(int). here documentation.

in case, since pixels either black or white, non 0 pixels white pixels.

this how utilize it,

int cal = countnonzero(image);

change image, per code.

c++ xcode osx opencv video-processing

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -