Facedetection on android use qt creator and opencv?

asked 2015-11-14 09:33:15 -0600

Sorry my english is bad! I need a help about it! Thís is my code!

#include<stdio.h>
#include<math.h>
#include<opencv/cv.h>
#include<opencv/highgui.h>
#include<opencv2/objdetect/objdetect.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<vector>
#include <QDebug>
using namespace cv; 
using namespace std;

int main()
{
qDebug()<<"aa";
CascadeClassifier face_cascade, eye_cascade;
if(!face_cascade.load("/mnt/shared/s/haarcascade_frontalface_alt2.xml")) {
    qDebug()<<"Error loading cascade file for face";
    return 1;
}
if(!eye_cascade.load("/mnt/shared/s/haarcascade_eye.xml")) {
    qDebug()<<"Error loading cascade file for eye";
    return 1;
}
//cho phep chup lai anh bang camera
VideoCapture capture(0); //-1, 0, 1 device id - 0 chinh la device su dung
if(!capture.isOpened())
{
    qDebug()<<"error to initialize camera";
    return 1;
}
Mat cap_img,gray_img; //Ma tran de luu anh
vector<Rect> faces, eyes; //Hinh chu nhat duoc cap nhat vi tri lien tuc
while(1)
{
    capture >> cap_img; //chup lai anh man hinh
    waitKey(10); //khoang thoi gian giua 2 lan chup lien tiep là 10 ms neu ko set thi se ko chup dc
    cvtColor(cap_img, gray_img, CV_BGR2GRAY); //Chuyen doi hinh anh tu mot khong gian mau khac
    cv::equalizeHist(gray_img,gray_img); //Cac bieu do cua hinh anhanh
    // su dung detectMultiscale de nhan dang doi tuong
    face_cascade.detectMultiScale(gray_img, faces, 1.1, 10, CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, cvSize(0,0), cvSize(300,300));
    for(int i=0; i < faces.size();i++)
    {
        Point pt1(faces[i].x+faces[i].width, faces[i].y+faces[i].height);
        Point pt2(faces[i].x,faces[i].y);
        Mat faceROI = gray_img(faces[i]);
        eye_cascade.detectMultiScale(faceROI, eyes, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30,30));
        for(size_t j=0; j< eyes.size(); j++)
        {
            //Point center(faces[i].x+eyes[j].x+eyes[j].width*0.5, faces[i].y+eyes[j].y+eyes[j].height*0.5);
            Point center( faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5 );
            int radius = cvRound((eyes[j].width+eyes[j].height)*0.25);
            circle(cap_img, center, radius, Scalar(255,0,0), 2, 8, 0);
        }
        rectangle(cap_img, pt1, pt2, cvScalar(0,255,0), 2, 8, 0);
    }
    imshow("Result", cap_img);
    waitKey(3);
    char c = waitKey(3);
    if(c == 27)
        break;
}
return 0;

}

this is my problem E/cv::error()( 1944): OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvWaitKey, file /builds/master_pack-android/opencv/modules/highgui/src/window.cpp, line 600

edit retag flag offensive close merge delete

Comments

unfortunately, it's just , what the error says: your highgui module was built without any (os)windowing support. did you build opencv locally ? can you show your cmake output ?

berak gravatar imageberak ( 2015-11-14 09:39:46 -0600 )edit

Sorry i don't know about cmake output! can you give me your email? i need help!

xuanduc gravatar imagexuanduc ( 2015-11-14 09:52:12 -0600 )edit

let's keep it here (and also public), so more folks can help.

berak gravatar imageberak ( 2015-11-14 10:00:02 -0600 )edit

Can you teach me about show cmake output?

xuanduc gravatar imagexuanduc ( 2015-11-14 10:15:54 -0600 )edit

just run it the same way, you did, when building the opencv libs, the copy / paste te output, and addi to your question (it won't fit into a comment)

or: cerr << cv::getBuildInformation() << endl;in c++

berak gravatar imageberak ( 2015-11-14 10:25:02 -0600 )edit

E/cv::error()( 1301): OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvWaitKey, file /builds/master_pack-android/opencv/modules/highgui/src/window.cpp, line 600 F/libc ( 1301): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 1321 (example.plainCV) I/DEBUG ( 122): pid: 1301, tid: 1321, name: example.plainCV >>> org.qtproject.example.plainCV <<< I/ActivityManager( 254): Process org.qtproject.example.plainCV (pid 1301) has died.

"org.qtproject.example.plainCV" died.

xuanduc gravatar imagexuanduc ( 2015-11-14 10:34:31 -0600 )edit

again, the problem is not in your program, but with the opencv libs. you will have to rebuild them with proper qt support.

berak gravatar imageberak ( 2015-11-14 23:53:33 -0600 )edit

Hello berak, i try it with another program and it run! Here is my .pro file

QT += core widgets multimedia

TARGET = plainCV

SOURCES += main.cpp

CONFIG += C++11 debug

MOBILITY =

INCLUDEPATH += /home/android/Downloads/OpenCV-android-sdk/sdk/native/jni/include

OPENCV3RDPARTYLIBS = /home/android/Downloads/OpenCV-android-sdk/sdk/native/3rdparty/libs/x86 OPENCVNATIVELIBS = /home/android/Downloads/OpenCV-android-sdk/sdk/native/libs/x86

LIBS += \ $$OPENCVNATIVELIBS/libopencv_ml.a \ $$OPENCVNATIVELIBS/libopencv_ts.a \ $$OPENCVNATIVELIBS/libopencv_core.a \ $$OPENCVNATIVELIBS/libopencv_flann.a \ $$OPENCVNATIVELIBS/libopencv_pho

xuanduc gravatar imagexuanduc ( 2015-11-15 01:40:36 -0600 )edit