首页 \ 问答 \ 使用opencv和qt进行人脸检测(Face detection using opencv and qt)

使用opencv和qt进行人脸检测(Face detection using opencv and qt)

我正在尝试使用opencv和qt实现实时人脸检测程序。代码是mainwindow.h

 #include <QMainWindow>
 #include <opencv/cv.h>
 #include <opencv/highgui.h>
 #include <QLabel>

 namespace Ui {
 class MainWindow;
 }

 class MainWindow : public QMainWindow
  {
   Q_OBJECT
   public:
 explicit MainWindow(QWidget *parent = 0);
~MainWindow();
Ui::MainWindow* _ui;
CvCapture* _capture;
IplImage*       _img;
CvHaarClassifierCascade* _cascade;
CvMemStorage*   _storage;
QList<CvScalar>  _colors;
QPixmap*         _pixmap;
QTimer*          _timer;
QLabel* labelCapture;
private slots:
void on_actionCapture_triggered();
 };
//#endif // MAINWINDOW_H

main.cpp中

  #include <QtGui/QApplication>
  #include "mainwindow.h"

   int main(int argc, char *argv[])
  {
   QApplication a(argc, argv);
   MainWindow w;
    w.show();

   return a.exec();
    }

mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "opencv/cv.h"
    #include "opencv/highgui.h"
    #include "opencv/cvaux.h"
    #include <QTimer>
    #include <QLabel>

    MainWindow::MainWindow(QWidget *parent) :
  QMainWindow(parent),
  _ui(new Ui::MainWindow)
  {
_ui->setupUi(this);
QLabel* labelCapture;
_capture = cvCaptureFromCAM( 0 );
_cascade = (CvHaarClassifierCascade*)cvLoad("haarcascade_frontalface_alt2.xml");
_storage = cvCreateMemStorage(0);

_colors << cvScalar(0.0,0.0,255.0) << cvScalar(0.0,128.0,255.0)
        << cvScalar(0.0,255.0,255.0) << cvScalar(0.0,255.0,0.0)
        << cvScalar(255.0,128.0,0.0) << cvScalar(255.0,255.0,0.0)
        << cvScalar(255.0,0.0,0.0) << cvScalar(255.0,0.0,255.0);

  _timer = new QTimer(this);
  connect(_timer, SIGNAL(timeout()), this, SLOT(on_actionCapture_triggered()));
  _timer->start(10);
  labelCapture=new QLabel();
   }

  MainWindow::~MainWindow()
  {
cvReleaseImage(&_img);
cvReleaseCapture(&_capture);
delete _ui;
  }

   void MainWindow::on_actionCapture_triggered()
   {
// Query camera for next frame
_img = cvQueryFrame( _capture );

if (_img)
{
    // Detect objects
    cvClearMemStorage( _storage );

    CvSeq* objects = cvHaarDetectObjects(_img,
                                         _cascade,
                                         _storage,
                                         1.1,
                                         3,
                                         CV_HAAR_DO_CANNY_PRUNING,
                                         cvSize( 100, 100 ));

    int n = (objects ? objects->total : 0);

    CvRect* r;
    // Loop through objects and draw boxes
    for( int i = 0; i < n; i++ )
    {
        r = ( CvRect* )cvGetSeqElem( objects, i );
        cvRectangle( _img,
                     cvPoint( r->x, r->y ),
                     cvPoint( r->x + r->width, r->y + r->height ),
                     _colors[i%8]
                    );
    }

    // Convert IplImage to QImage
    QImage image = QImage((const uchar *)_img->imageData,
                                         _img->width,
                                         _img->height,
                                         QImage::Format_RGB888).rgbSwapped();
    _pixmap = new QPixmap(QPixmap::fromImage(image));
     _ui->labelCapture->setPixmap(*_pixmap);
   }
   }

但我得到以下错误...在函数on_action_capture_triggered()类ui :: mainWindow没有名为'labelCapture'的成员请帮助....


I am trying to implement a real time face detection program using opencv and qt.The code is mainwindow.h

 #include <QMainWindow>
 #include <opencv/cv.h>
 #include <opencv/highgui.h>
 #include <QLabel>

 namespace Ui {
 class MainWindow;
 }

 class MainWindow : public QMainWindow
  {
   Q_OBJECT
   public:
 explicit MainWindow(QWidget *parent = 0);
~MainWindow();
Ui::MainWindow* _ui;
CvCapture* _capture;
IplImage*       _img;
CvHaarClassifierCascade* _cascade;
CvMemStorage*   _storage;
QList<CvScalar>  _colors;
QPixmap*         _pixmap;
QTimer*          _timer;
QLabel* labelCapture;
private slots:
void on_actionCapture_triggered();
 };
//#endif // MAINWINDOW_H

main.cpp

  #include <QtGui/QApplication>
  #include "mainwindow.h"

   int main(int argc, char *argv[])
  {
   QApplication a(argc, argv);
   MainWindow w;
    w.show();

   return a.exec();
    }

mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "opencv/cv.h"
    #include "opencv/highgui.h"
    #include "opencv/cvaux.h"
    #include <QTimer>
    #include <QLabel>

    MainWindow::MainWindow(QWidget *parent) :
  QMainWindow(parent),
  _ui(new Ui::MainWindow)
  {
_ui->setupUi(this);
QLabel* labelCapture;
_capture = cvCaptureFromCAM( 0 );
_cascade = (CvHaarClassifierCascade*)cvLoad("haarcascade_frontalface_alt2.xml");
_storage = cvCreateMemStorage(0);

_colors << cvScalar(0.0,0.0,255.0) << cvScalar(0.0,128.0,255.0)
        << cvScalar(0.0,255.0,255.0) << cvScalar(0.0,255.0,0.0)
        << cvScalar(255.0,128.0,0.0) << cvScalar(255.0,255.0,0.0)
        << cvScalar(255.0,0.0,0.0) << cvScalar(255.0,0.0,255.0);

  _timer = new QTimer(this);
  connect(_timer, SIGNAL(timeout()), this, SLOT(on_actionCapture_triggered()));
  _timer->start(10);
  labelCapture=new QLabel();
   }

  MainWindow::~MainWindow()
  {
cvReleaseImage(&_img);
cvReleaseCapture(&_capture);
delete _ui;
  }

   void MainWindow::on_actionCapture_triggered()
   {
// Query camera for next frame
_img = cvQueryFrame( _capture );

if (_img)
{
    // Detect objects
    cvClearMemStorage( _storage );

    CvSeq* objects = cvHaarDetectObjects(_img,
                                         _cascade,
                                         _storage,
                                         1.1,
                                         3,
                                         CV_HAAR_DO_CANNY_PRUNING,
                                         cvSize( 100, 100 ));

    int n = (objects ? objects->total : 0);

    CvRect* r;
    // Loop through objects and draw boxes
    for( int i = 0; i < n; i++ )
    {
        r = ( CvRect* )cvGetSeqElem( objects, i );
        cvRectangle( _img,
                     cvPoint( r->x, r->y ),
                     cvPoint( r->x + r->width, r->y + r->height ),
                     _colors[i%8]
                    );
    }

    // Convert IplImage to QImage
    QImage image = QImage((const uchar *)_img->imageData,
                                         _img->width,
                                         _img->height,
                                         QImage::Format_RGB888).rgbSwapped();
    _pixmap = new QPixmap(QPixmap::fromImage(image));
     _ui->labelCapture->setPixmap(*_pixmap);
   }
   }

But iam getting the following error... On function on_action_capture_triggered() class ui::mainWindow has no member named ‘labelCapture’ pls help....


原文:https://stackoverflow.com/questions/15324596
更新时间:2023-08-25 15:08

最满意答案

得到了解决方案..!

我在R中使用了“Shiny”库。这将r脚本转换为app,然后可以使用简单的http请求从asp.net调用。


Got the solution..!

I used "Shiny" a library in R. This converts the r script into an app which can then be called from asp.net using simple http request.

相关问答

更多
  • 任何你不使用asp:Label的原因? 您无法找到“标签”,因为它是一个html控件,也就是客户端控件。 使用
  • 听起来像你正在使用自动化来控制Excel应用程序本身? 一些快速信息: Excel被安装在Web服务器上 这通常是一个坏主意,因为Excel应用程序不是一个旨在被服务器自动化的应用程序。 事情可能会挂起,因为应用程序正在等待某个对话框中的用户输入。 而且它不能同时处理来自多个用户的操作。 如果最终目标是从excel文件中提取数据并将其放入sql服务器,那么我宁愿建议您使用Jet OLEDB提供程序从Web应用程序中检索excel文件中的数据,然后让它将数据提供给sql server,或让sql server ...
  • 它几乎适用于此,但“kommune”仍然没有100%工作 protected void ButtonSearch_Click(object sender,EventArgs e){ string statement = @"SELECT * FROM brugere"; string whereConcatenator = " WHERE "; if (DropDownListSøger.SelectedItem != null) { statement ...
  • 如果我正确理解你的问题,你想在服务器端创建一个数组并在客户端读取它。 请参阅此链接以获取有关如何将数组从服务器传递到客户端的教程。 基本上,你想使用ClientScriptManager.RegisterArrayDeclaration方法为数组添加值。 然后,您可以轻松地在JavaScript中阅读它。 服务器端: string arrayName = "MyArray"; Page.ClientScript.RegisterArrayDeclaration(arrayName , "'value1'") ...
  • 它无法正常工作,因为您正在调用Response.Redirect 。 在当前页面上发生的任何事情都将无效,因为新页面将在呈现当前页面之前立即重定向。 你有几个选择,但我认为你想要的是...... protected void Button1_Click(object sender, EventArgs e) { Response.Write("