Ask Your Question

Sachin Bhatia's profile - activity

2016-08-27 04:37:13 -0600 commented question Program crashes giving unhelpful exit codes

@berak - but while debugging my program symbols from the Microsoft Symbol server are downloaded. Does this make up for the absence of PDB or is it a completely different thing?

2016-08-25 05:09:05 -0600 commented question Program crashes giving unhelpful exit codes

@berak - I set a breakpoint just before the eye detection function is called and stepped into the function call given below, executing a statement at a time.

eye_cascade.detectMultiScale(gray, eyes, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(10, 10));

The function call ends with with the control shifting to the console window and control does not return to code regardless of anything I press. What do you suggest I do to uncover information that would help identify what the problem is?

I've had someone review my code and they tried catching for exceptions but did not find any.

2016-08-23 06:56:45 -0600 commented question Program crashes giving unhelpful exit codes

@berak - the sample objectdetection2.cpp program doesn't work as well. All I get is a single frame after which the program crashes. However I had the task manager window open and under disk, percentage used was 100%. 60% of memory is used when the program is supposedly running. Are these observations of any utility?

2016-08-23 03:39:33 -0600 commented question Program crashes giving unhelpful exit codes

I've checked again as you asked and I can confirm that the linker is configured correctly. link text

2016-08-23 01:28:14 -0600 commented question Program crashes giving unhelpful exit codes

@berak - I have worked through these possibilities. As I mentioned before the program worked fine before I added the eye detection feature. If you can not detect anything amiss from the function definition, I'll add the code I left out.

2016-08-20 09:42:25 -0600 commented question Program crashes giving unhelpful exit codes

@berak - I made some edits to the code as I was posting the question. Left out some parts I considered irrelevant. Sorry for making you comment look out of context.

2016-08-20 09:32:18 -0600 received badge  Editor (source)
2016-08-20 08:43:20 -0600 asked a question Program crashes giving unhelpful exit codes

I'm building a face and eye detecting program using OpenCV 3.1 using Visual Studio 2015. I've changed the sample code provided to suit my purposes. The function definition is given below.

      #include "opencv2/objdetect/objdetect.hpp"
      #include "opencv2/highgui/highgui.hpp"
      #include "opencv2/imgproc/imgproc.hpp"

      #include <iostream>
      #include <stdio.h>

      using namespace std;
      using namespace cv;

      // Function Headers
      void detectAndDisplay(Mat frame);
      void CallBackFunc(int event, int x, int y, int flags, void* userdata);

      // Global variable
      string face_cascade_name = "haarcascade_frontalface_alt.xml";
      CascadeClassifier face_cascade;
      string eye_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
      CascadeClassifier eye_cascade;

      string window_name = "Capture - Face detection";

  // Function main
      int main(void)
            {
                VideoCapture capture(0);

                if (!capture.isOpened())  // check if we succeeded
                    return -1;

                // Load the cascades
                if (!face_cascade.load(face_cascade_name)){ printf("--(!)Error loading\n"); return (-1); }
                if (!eye_cascade.load(eye_cascade_name)){ printf("--(!)Error loading\n"); return (-1); }

                // Read the video stream
                Mat frame;

                for (;;)
                {
                    capture >> frame;

                    if (!frame.empty())
                        detectAndDisplay(frame);

                    else
                    {
                        printf(" --(!) No captured frame -- Break!");
                        break;
                    }

                    int c = waitKey(10);

                    if (27 == char(c))
                        break;
                }

                return 0;
            }

void detectAndDisplay(Mat frame)
{
   std::vector<Rect> faces, eyes;

   Mat frame_gray, crop, gray;
   string text; 
   stringstream sstm;          

   cvtColor(frame, frame_gray, COLOR_BGR2GRAY);
   equalizeHist(frame_gray, frame_gray);

    // Detect faces 
    face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(40, 40));

    Point cen_win(frame.size().width / 2, frame.size().height / 2);
    circle(frame, cen_win, 1, Scalar(0, 0, 255), CV_FILLED);

    size_t ic = 0; // ic is index of current element
    unsigned long ac = 0; // ac is area of current element

    size_t ib = 0; // ib is index of biggest element
    unsigned long ab = 0; // ab is area of biggest element

     for (ic = 0; ic < faces.size(); ic++) // Iterate through all detected faces
           {
                ac = faces[ic].area();
                ab = faces[ib].area();

                if (ac > ab)
                    ib = ic; 
           }

      if(faces.size())
          {
               Point pt1(faces[ib].x, faces[ib].y);
               Point pt2((faces[ib].x + faces[ib].width), (faces[ib].y + faces[ib].height));
               rectangle(frame, pt1, pt2, Scalar(0, 255, 0), 2, 8, 0); 

               crop = frame(faces[ib]);
               cvtColor(crop, gray, COLOR_BGR2GRAY);
               equalizeHist(gray, gray);
               eye_cascade.detectMultiScale(gray, eyes, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(10, 10));


               if(eyes.size())  
                      {
                           Point Ept1, Ept2;        

                           for (int i = 0; i < eyes.size(); ++i)
                             {
                              Ept1.x = eyes[i].x; 
                              Ept1.y = eyes[i].y;

                                  Ept2.x = eyes[i].x + eyes[i].width; 
                              Ept2.y = eyes[i].y + eyes[i].height;

                              rectangle(frame, Ept1, Ept2, Scalar(0, 255, 0), 2, 8, 0);
                                }
                       } 

                 Point cen_rec(faces[ib].x + faces[ib].width / 2, faces[ib].y + faces[ib].height / 2);
                 circle(frame, cen_rec, 1, Scalar(0, 0, 255), CV_FILLED); //Marks the center of detected face.                                          

                // Output text
                sstm << "Crop area size: " << faces[ib].width << "x" << faces[ib].height << " Size of window: " << frame.size().width << '*' << frame.size().height;
                text = sstm.str();
                putText(frame, text, cvPoint(30, 30), FONT_HERSHEY_COMPLEX_SMALL, 0.8, cvScalar(0, 0, 255), 1, CV_AA);
                sstm.clear();
                sstm.str(string());

                double percentage;
                percentage = ((double)ab) / (frame.size().width * frame.size().height) * 100;
                sstm << "Percentage: " << percentage << " Tilt: " << (cen_rec.y - cen_win.y)/10 << " Pan: " << (cen_rec.x - cen_win ...
(more)