如何在OpenCV中使用gstream

时间:2017-07-20 06:10:17

标签: c++ opencv gstreamer imx6 gstreamer-1.0

我正在使用İ.MXQ6sabresd开发板。我想将gstreamerOpencv一起使用。我想用OpenCV捕获和处理视频帧。但我的代码不起作用。

我该怎么做?

我的代码如下:

#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdlib.h>


using namespace std;
using namespace cv; 

String window_name = "Face Detection";


void detectFaces(Mat frame, int frameno) { 

CascadeClassifier face_cascade;
face_cascade.load("/usr/examples/facevide/haarcascade_frontalface_alt.xml");

CascadeClassifier eye_cascade;
eye_cascade.load("/usr/examples/facevide/haarcascade_eye.xml");

std::vector<Rect> faces; 
face_cascade.detectMultiScale( frame, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE,
Size(30, 30) );
std::vector<Rect> eyes;
eye_cascade.detectMultiScale( frame, eyes, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE,
Size(100, 100) );

std::ostringstream name;
name << "rotated_im_" << frameno << ".jpg";
for( int i = 0; i < faces.size(); i++ ){
Point center(faces[i].x + faces[i].width/2, faces[i].y + faces[i].height/2);

ellipse(frame, center, Size(faces[i].width/2, faces[i].height/2), 0, 0, 360, Scalar( 255, 0,
255 ), 4, 8, 0 );

for( int j = 0; j < eyes.size(); j++ )
 {
Point eyes_center( eyes[j].x + eyes[j].width/2, eyes[j].y + eyes[j].height/2 );

int radius = cvRound( (eyes[j].width + eyes[j].height)*0.25 );
circle( frame, eyes_center, radius, Scalar( 255, 0, 0 ), 4, 8, 0 );
}

}
imwrite(name.str(), frame); // Display frame
}

int main() {

//VideoCapture cap("gst-launch-1.0 imxv4l2src ! autovideosink ! appsink");

//VideoCapture cap("gst-launch-1.0 autovideosrc ! autovideosink");

//VideoCapture cap(" mfw_v4lsrc ! ffmpegcolorspace ! video/x-raw-rgb ! appsink");

//VideoCapture cap("v4l2src ! video/x-raw, framerate=30/1, width=640, height=480, format=RGB ! videoconvert ! appsink");

VideoCapture cap("gst-launch mfw_v4lsrc num-buffers=1 !  jpegenc ! filesink location=sample.jpeg"); 

Mat frame;

int i = 0;

while(cap.read(frame)) {

detectFaces(frame, i);

i++;
                          }
                     }

0 个答案:

没有答案