Ask Your Question

lenteken's profile - activity

2020-08-15 04:07:09 -0500 received badge  Famous Question (source)
2019-05-02 09:10:31 -0500 received badge  Notable Question (source)
2017-09-02 17:52:43 -0500 marked best answer Crop Image using hough circle

I want to crop the image using hough circle. I saw in some forum that they used Rect in ROI but it is not what I need because I want to crop the iris from the eye. Is there any possible solution?

2017-07-20 13:59:21 -0500 received badge  Popular Question (source)
2017-05-29 05:13:19 -0500 received badge  Notable Question (source)
2016-11-07 08:45:02 -0500 received badge  Famous Question (source)
2016-10-05 01:52:41 -0500 received badge  Famous Question (source)
2016-03-10 06:25:14 -0500 received badge  Popular Question (source)
2015-09-01 18:57:13 -0500 received badge  Famous Question (source)
2015-06-25 07:16:20 -0500 received badge  Notable Question (source)
2015-06-19 15:49:25 -0500 received badge  Famous Question (source)
2015-04-26 22:18:09 -0500 received badge  Notable Question (source)
2015-03-19 05:10:53 -0500 received badge  Notable Question (source)
2015-01-05 03:28:03 -0500 received badge  Popular Question (source)
2014-12-09 13:54:16 -0500 marked best answer Measure the Length and Width of the bounding Box

This is only simple application of opencv but I don't know how to do it . I will apply this application to measure the dimension of the object(Height and Width). Look at this video what I want to do. http://www.youtube.com/watch?v=bcswZLwhTUI

image description

Please look at this code if it is correct.

   int main(int, char**)
 {
 Mat threshold_output;
 vector<vector<Point> > contours;
 vector<Vec4i> hierarchy;
 RNG rng(12345);

 CvCapture* capture = cvCaptureFromCAM(0);

 cv::Mat frame; cv::Mat src_gray;

while(true) {
    frame = cvQueryFrame( capture );

    cvtColor( frame,src_gray, CV_BGR2GRAY ); // produces out2, a one-channel image (CV_8UC1)
    blur( src_gray, src_gray, Size(11,11) );

    threshold( src_gray, threshold_output, 100, 200, CV_THRESH_BINARY_INV);

    findContours( threshold_output, contours, hierarchy,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );

    /// Find the rotated rectangles and ellipses for each contour
    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( frame, rect_points[j], rect_points[(j+1)%4], color, 1, 8 );
     }

 namedWindow( "Contours", CV_WINDOW_AUTOSIZE );
 imshow( "Contours", frame );

    cvWaitKey(33);
}
return 0;

} `

2014-12-02 02:20:55 -0500 received badge  Notable Question (source)
2014-10-22 01:30:56 -0500 received badge  Popular Question (source)
2014-08-20 06:00:58 -0500 received badge  Popular Question (source)
2014-05-29 05:38:36 -0500 received badge  Nice Question (source)
2014-05-14 08:06:24 -0500 received badge  Popular Question (source)
2013-09-04 02:58:45 -0500 commented answer opencv in windows form

How can I initialize openFileDialog1? can you show me some code ?

2013-09-04 01:50:14 -0500 asked a question opencv in windows form

I am using now windows form in visual c++. I got an error:

error C2065: 'Filename' : undeclared identifier

error C2065: 'openFileDialog1' : undeclared identifier

error C2227: left of '->FileName' must point to class/struct/union/generic type

I don't know what is wrong in my code. Anyone who can solve this problem?

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
            cv::Mat img;

            img = cv::imread(openFileDialog1->FileName, CV_LOAD_IMAGE_COLOR);

            System::Drawing::Graphics^ graphics = pictureBox1->CreateGraphics();
            System::IntPtr ptr(img.ptr());
            System::Drawing::Bitmap^ b  = gcnew System::Drawing::Bitmap(img.cols,img.rows,img.step,System::Drawing::Imaging::PixelFormat::Format24bppRgb,ptr);
            System::Drawing::RectangleF rect(0,0,pictureBox1->Width,pictureBox1->Height);
            graphics->DrawImage(b,rect);


         }
2013-08-27 02:59:27 -0500 commented answer Best method to count the black and white pixels of the image.

I tried the code but the result is incorrect because the program didn't count the black pixels. Take a look at this code I've done. http://answers.opencv.org/question/19302/count-the-pixel-black-or-white-in-real-time/

2013-08-27 02:56:08 -0500 commented answer Best method to count the black and white pixels of the image.

I count now the black pixels. Thanks,I understand now the program. But the value I got is increment. How can I get the total pixels because I will use it in real time. The result is different when I convert it into real time. Please respond

2013-08-26 14:09:34 -0500 commented answer Count the pixel (black or white) in real time.

sorry but I don't understand. Please edit my code so I can understand it easily.

2013-08-26 13:15:13 -0500 commented answer Count the pixel (black or white) in real time.

In that part, I count the black pixels but the result is wrong.

2013-08-26 08:48:34 -0500 commented answer Count the pixel (black or white) in real time.

I used the countNonZero but I can't get the black pixels. Please look at the code that I have update.

2013-08-22 12:17:55 -0500 asked a question Count the pixel (black or white) in real time.

I need to count the black and white pixels of the object in REAL TIME. What is the best method to use for this ? In my program, First I get the biggest contour .The next process is to count the pixels(black) of the object that have no mask but I don't know how to do it. Thanks in advance. image description

 #include <opencv2/imgproc/imgproc.hpp>
 #include <opencv2/highgui/highgui.hpp>

 using namespace cv;
 int main(int argc, char** argv)
 {
 vector<Vec4i> hierarchy;
     CvCapture* capture = cvCaptureFromCAM(0);
 cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 270);
 cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 190);

    cv::Mat src;

    while(true) {
        src = cvQueryFrame( capture );

    Mat gray;
    cvtColor(~src, gray, CV_BGR2GRAY);
    //medianBlur(gray,gray,27);
    threshold(gray, gray, 220, 255, THRESH_BINARY);
    vector<vector<Point> > contours;
    findContours( gray.clone(), contours, hierarchy,CV_RETR_EXTERNAL,
    CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );


    for (int i = 0; i < contours.size(); i++)
    {
        double area =contourArea(contours[i]);
        Rect rect = boundingRect(contours[i]);

        if (area >= 30&& abs(1 - ((double)rect.width / (double)rect.height)) <=
            0.1)   
        {

            Mat mask = Mat::zeros(gray.rows, gray.cols, CV_8UC1);
            drawContours( mask, contours, i, CV_RGB(255,255,255), -1, 8,
            vector<Vec4i>(), 0,Point() ); //masking//
            Mat crop(src.rows, src.cols, CV_8UC3);
            crop.setTo(Scalar(0,0,255));
            src.copyTo(crop, mask);


            Mat masked;
            gray.copyTo(masked, mask);
            int count_black = cv::countNonZero(masked == 255);
            printf("count_black = %d\n",count_black);
            printf("ContourArea = %.0f\n\n",
                  ((contourArea(contours[i]))+( arcLength( contours[i],
                    true )/2)));


           imshow("cropped", crop);
           imshow("source", src);
            waitKey(33);
        }


    }



}
}
2013-08-17 07:33:14 -0500 commented answer Best method to count the black and white pixels of the image.

same result value at the code you give first.

2013-08-16 23:31:17 -0500 commented answer Best method to count the black and white pixels of the image.

I used ' gray' but I got same result :(

2013-08-16 13:49:47 -0500 commented answer Best method to count the black and white pixels of the image.

I try your code but I got same value. In image.copyTo(masked, mask); image is undefined. what is the correct code for that? Sorry I am very newbie .

2013-08-16 13:34:39 -0500 commented answer Best method to count the black and white pixels of the image.

It run successfully thanks, :) . The value I get is count_white = 450 to 598 and black_count = 0. Is the value correct?

2013-08-16 07:25:50 -0500 commented answer Best method to count the black and white pixels of the image.

I try this code also but this code count the black and white pixels of the mask not the image.

2013-08-16 07:24:20 -0500 commented answer Best method to count the black and white pixels of the image.

what do you mean replace the src ? Can you please edit the code above. Thanks :)

2013-08-16 03:36:00 -0500 marked best answer Best method to count the black and white pixels of the image.

After I masked the image and get the part I wanted. The next process is to count the black and white pixels of the unmasked part of the image but I don't know how to do it. Anyone who can give me the method to solve this.

image description

#include "opencv\cvaux.h" #include "opencv\cxmisc.h" #include "opencv\highgui.h" #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <stdlib.h>

using namespace std; using namespace cv;

int main(int, char**) { Mat threshold_output; vector<vector<point> > contours; vector<vec4i> hierarchy; RNG rng(12345);

     CvCapture* capture = cvCaptureFromCAM(0);
 cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 270);
 cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 190);

    cv::Mat frame; cv::Mat src_gray;

    while(true) {
        frame = cvQueryFrame( capture );

        cvtColor( frame,src_gray, CV_BGR2GRAY );
        medianBlur( src_gray, src_gray, 25 );
        threshold( src_gray.clone(), threshold_output, 20, 255,CV_THRESH_BINARY_INV);
        findContours( threshold_output.clone(), contours,hierarchy,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );


        for (int i = 0; i < contours.size(); i++)
        {
            double area =contourArea(contours[i]);
            Rect rect = boundingRect(contours[i]);

            if (area >= 30 && abs(1 - ((double)rect.width /(double)rect.height)) <= 0.1)   
            {


                   Mat mask = Mat::zeros(threshold_output.rows, threshold_output.cols, CV_8UC1);
                   drawContours( mask, contours,i , Scalar::all(255), -1);
                   Mat crop(frame.rows, frame.cols, CV_8UC3);
                   crop.setTo(Scalar(255,255,255));
                   frame.copyTo(crop, mask);

                    int count_black = 0;
                    int count_white = 0;
                    int black_total;
                    int white_total;

                    for( int y = 0; y < frame.rows; y++ ) 
                    {
                      for( int x = 0; x < frame.cols; x++ ) 
                      {
                        if ( mask.at<uchar>(y,x) != 0 ) {
                          // change this to to 'src.atuchar>(y,x) == 255' 
                          // if your img has only 1 channel
                          if ( frame.at<cv::Vec3b>(y,x) == cv::Vec3b(0,0,0) ) 
                          {
                            count_black++;
                            black_total = count_black + count_black ;
                            printf("black= %d",black_total);

                          } 

                        }
                    }

                    }
                   imshow( "frame", frame );
                   imshow("crop",crop);
                   waitKey(33);
            }   


        }


    }

}