Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何以及在何处使用basler cam和QT实现opencv人脸检测代码_C++_Qt_Opencv_Camera_Face Detection - Fatal编程技术网

C++ 如何以及在何处使用basler cam和QT实现opencv人脸检测代码

C++ 如何以及在何处使用basler cam和QT实现opencv人脸检测代码,c++,qt,opencv,camera,face-detection,C++,Qt,Opencv,Camera,Face Detection,我在尝试让opencv人脸检测与我的basler cam在QT中工作时遇到了一些麻烦;我尝试了许多不同的方法来实现它,在网上使用了许多不同的示例代码。我似乎根本无法让它发挥作用;此外,我所做的尝试降低了我的帧速率 我用basler摄像机拍摄视频的代码工作得很好,我只是在实现人脸检测部分时遇到了问题。我将在下面粘贴到目前为止我为相机和opencv所用的代码。代码确实会不时出现一些红色框,但它并不稳定。我也得到了这个错误 Failed to load OpenCL runtime 我不确定我做错了

我在尝试让opencv人脸检测与我的basler cam在QT中工作时遇到了一些麻烦;我尝试了许多不同的方法来实现它,在网上使用了许多不同的示例代码。我似乎根本无法让它发挥作用;此外,我所做的尝试降低了我的帧速率

我用basler摄像机拍摄视频的代码工作得很好,我只是在实现人脸检测部分时遇到了问题。我将在下面粘贴到目前为止我为相机和opencv所用的代码。代码确实会不时出现一些红色框,但它并不稳定。我也得到了这个错误

Failed to load OpenCL runtime
我不确定我做错了什么,还有没有一种方法可以在不降低帧速率的情况下实现人脸检测,因为它已经很慢了

  #include "mainwindow.h"
#include "ui_mainwindow.h"

#include <opencv2/opencv.hpp>

#include <pylon/PylonIncludes.h>
//#include <pylon/PylonGUI.h>
//#ifdef PYLON_WIN_BUILD
//#include <pylon/PylonGUI.h>
//#endif

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <iostream>
#include<time.h>
#include<stdlib.h>


using namespace cv;

// Namespace for using pylon objects.
using namespace Pylon;


// Namespace for using cout.
using namespace std;


static const uint32_t c_countOfImagesToGrab = 100;


cv::CascadeClassifier faceCade;

String faceCascadeName = "/usr/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml";
String FaceDetectWindow = "Face Detector Window";
String FaceDetectGrayWindow = "Face Detector Gray Window";
size_t i;

vector<Rect> faces;

  cv::Mat camFrames, grayFrames;

int main()
{


    // The exit code of the sample application.
    int exitCode = 0;

    // Automagically call PylonInitialize and PylonTerminate to ensure
    // the pylon runtime system is initialized during the lifetime of this object.
    Pylon::PylonAutoInitTerm autoInitTerm;

faceCade.load( faceCascadeName );

    CGrabResultPtr ptrGrabResult;
    namedWindow("CV_Image",WINDOW_AUTOSIZE);



        CInstantCamera camera( CTlFactory::GetInstance().CreateFirstDevice());
          cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
           camera.Open();

           GenApi::CIntegerPtr width(camera.GetNodeMap().GetNode("Width"));
               GenApi::CIntegerPtr height(camera.GetNodeMap().GetNode("Height"));
               Mat cv_img(width->GetValue(), height->GetValue(), CV_8UC3);

               camera.StartGrabbing();
                  CPylonImage image;
                  CImageFormatConverter fc;
                   fc.OutputPixelFormat = PixelType_BGR8packed;

                   while(camera.IsGrabbing()){
                      camera.RetrieveResult( 5000, ptrGrabResult, TimeoutHandling_ThrowException);
if (ptrGrabResult->GrabSucceeded()){

    fc.Convert(image, ptrGrabResult);


                   cv_img = cv::Mat(ptrGrabResult->GetHeight(),     ptrGrabResult->GetWidth(), CV_8UC3,(uint8_t*)image.GetBuffer());





                   //cvtColor(cv_img, grayFrames, cv::COLOR_BGR2GRAY);
                    //equalizeHist(grayFrames, grayFrames);
                    faceCade.detectMultiScale(cv_img, faces, 1.1, 2, 0, Size(160, 160));




                    for (int i = 0; i < faces.size(); i++)
                  {
                        //Mat faceROI = grayFrames(faces[i]);
                        rectangle(cv_img, Rect(faces[i].x - 25,faces[i].y - 25,faces[i].width + 35 ,faces[i].height + 35),  Scalar(0, 0, 255), 1, 1, 0);
                        Point center(faces[i].x + faces[i].width * 0.5,faces[i].y + faces[i].height * 0.5);



}


                   imshow("CV_Image",cv_img);
                   //imshow("FaceDetectGrayWindow", grayFrames);
                     waitKey(1);
                     if(waitKey(30)==27){
                                          camera.StopGrabbing();
                                    }
}

                   }


}
}
#包括“mainwindow.h”
#包括“ui_main window.h”
#包括
#包括
//#包括
//#ifdef塔架\u赢得\u建造
//#包括
//#恩迪夫
#包括“opencv2/highgui/highgui.hpp”
#包括“opencv2/imgproc/imgproc.hpp”
#包括“opencv2/core/core.hpp”
#包括
#包括
#包括
#包括
#包括
使用名称空间cv;
//用于使用挂架对象的命名空间。
使用名称空间挂架;
//用于使用cout的命名空间。
使用名称空间std;
图像抓取的静态常数32_t c_计数=100;
cv::cascade;
String faceCascadeName=“/usr/share/OpenCV/haarcascade/haarcascade\u frontalface\u alt.xml”;
字符串FaceDetectWindow=“人脸检测窗口”;
字符串FaceDetectGrayWindow=“人脸检测器灰色窗口”;
尺寸i;
向量面;
cv::Mat camFrames,灰色框架;
int main()
{
//示例应用程序的退出代码。
int-exitCode=0;
//自动调用PylonInitialize和PylonTerminate以确保
//pylon运行时系统在此对象的生存期内初始化。
Pylon::PylonAutoInitTerm autoInitTerm;
faceCade.load(faceCascadeName);
cGrabResultPtrGrabResult;
namedWindow(“CV_图像”,窗口自动调整大小);
CInstantCamera摄像机(CTlFactory::GetInstance().CreateFirstDevice());
cout()){
fc.转换(图像、ptrGrabResult);
cv_img=cv::Mat(ptrGrabResult->GetHeight(),ptrGrabResult->GetWidth(),cv_8UC3,(uint8_t*)image.GetBuffer();
//CVT颜色(cv_img,灰色边框,cv::COLOR_bgr2灰色);
//均衡器历史(灰色帧,灰色帧);
faceCade.detectMultiScale(cv_img,faces,1.1,2,0,大小(160160));
对于(int i=0;i

谢谢你

我不太确定,但是
检测多尺度
功能可以使用cv_8u类型的图像,我看到你在使用cv_8uc3,我知道cv_8u是8位像素,有1个通道,cv_8uc3只有8位,但有3个通道,你需要将图像转换为灰度,我看到你这么做了,但你评论了?!!! 看看这个链接

也许这会解决你的问题,有些人建议你安装opencl

sudo apt-get install ocl-icd-opencl-dev

我对此不太确定,但
detectMultiScale
函数适用于cv_8u类型的图像,正如我看到的,您正在使用cv_8uc3,我知道cv_8u是8位像素,有1个通道,cv_8uc3是8位,但有3个通道,您需要将图像转换为灰度,我看到您这样做了,但您对此进行了评论?!!! 看看这个链接

也许这会解决你的问题,有些人建议你安装opencl

sudo apt-get install ocl-icd-opencl-dev
你试过这个吗