AnsweredAssumed Answered

How can ı use gstream with OpenCV

Question asked by Yaşarcan İtişgen on Jul 19, 2017
Latest reply on Jul 30, 2017 by Joan Xie

Hi,

 

I am using İ.MXQ6sabresd development board. I want to use gstreamer with Opencv. I want to capturing and processing video frames with OpenCV .  But my code did not work.How can ı do it ? My code:

 

#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");
//const char* pipe =  "rtspsrc location=\"rtsp://192.168.0.220:554/user=admin&password=admin&channel=1&
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++;
                          }
                     }

Thank you.

Yasarcan

 

Outcomes