1

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 does not work.

How can I do it ?

My code is as below :

#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++;
                          }
                     }
4
  • are you using a usb webcam for video input? Which operating system are you using? Commented Jul 20, 2017 at 6:19
  • stackoverflow.com/questions/37339184/… Commented Jul 20, 2017 at 6:44
  • For gstreamer-1.0 ffmpegcolorspace was replaced with videoconvert. Could you try VideoCapture cap(" mfw_v4lsrc ! videoconvert ! appsink") or VideoCapture cap(" mfw_v4lsrc ! mfw_ipucsc ! appsink") ? Commented Jul 20, 2017 at 11:41
  • I use a camera connected to the board. Ubuntu. @ganeshredcobra Commented Jul 25, 2017 at 11:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.