Ask Your Question
0

I want to create interface and run within button click

asked 2013-06-20 01:10:06 -0500

Pirass gravatar image

updated 2013-06-20 04:12:38 -0500

berak gravatar image

I want to count the pedestrian amount from image.so it's working. now i have to do within button click. if i click button, this function want to run and count the pedestrian. my codes here. how can i do that. help me.

#include "stdafx.h"
#include <stdio.h>
#include <cv.h>
#include <iostream>
#include <highgui.h>

using namespace cv;
using namespace std;
void detect(IplImage *faces);
int main()
{
  freopen("out.txt","w",stdout);
  CascadeClassifier cascade;

  if (!cascade.load("haarcascade_frontalface_alt.xml"))
    return -1;

  Mat src = imread("people1.jpg");
  if (src.empty())
    return -1;

  Mat gray;
  cvtColor(src, gray, CV_BGR2GRAY);
  equalizeHist(gray, gray);

  vector<Rect> faces;
  cascade.detectMultiScale(gray, faces, 1.2, 3);

  for (int i = 0; i < faces.size(); i++)
  {
    Rect r = faces[i];
    rectangle(src, Point(r.x, r.y), Point(r.x + 5, r.y + 5), CV_RGB(0,255,0));
  }
  std::cout << "Total: " << faces.size() << " faces" << std::endl;
  imshow("src", src);
  waitKey(0);

  return 0;

}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-06-20 04:11:12 -0500

berak gravatar image

if you got qt support, you could use that.

if all you need is to "click", maybe a simple mousehandler does the trick:

void onmouse( int event, int x, int y, int d, void *p )
{
     bool *trigger = (bool*)p;
     *trigger = (event && d);
}

int main()
{
    VideoCapture cap(0);
    Mat frame; 
    namedWindow("processed", 1);
    bool trigger = false;
    cv::setMouseCallback( "video", onmouse, &trigger );
    for(;;) {
        cap >> frame;
        if(frame.empty()) break;
            if ( trigger )
            {
                // your code here ..
            }
        imshow("video", frame);
        if(waitKey(30) >= 0) break;
    }   
    return 0;
}
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-06-20 01:10:06 -0500

Seen: 97 times

Last updated: Jun 20 '13