Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:11205899
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
///////////////////////////////C++///////////////////////////////////////////
This is the main part, a snippet of a face detection program, runable if you have OpenCV installed
 
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/imgproc/imgproc_c.h"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
 
//My c wrapper for vector<Rect>, to convert a vector<Rect> to a c array. Rect is a C++ class
 
typedef vector<Rect> vector_Rect;
 
Rect* std_vectorrToCArray(vector_Rect* s) {
return s->data();
}
 
// my c wrapper for OpenCV's detectMultiScale here: http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html?highlight=detectmultiscale#cascadeclassifier-detectmultiscale
 
void cv_CascadeClassifier_detectMultiScale(CascadeClassifier* self, Mat* image, vector_Rect* objects, double scaleFactor, int minNeighbors, int flags, Size* minSize, Size* maxSize) {
self->detectMultiScale(*image, *objects, scaleFactor, minNeighbors, flags, *minSize, *maxSize);
}
 
 
// Global variables
// create data to use in detectMultiScale
string face_cascade_name = "/home/w/Desktop/opencv-master/data/haarcascades/haarcascade_frontalface_alt.xml";
CascadeClassifier face_cascade;
 
int main()
{ //Create c++ vector
std::vector<Rect> faces;
Mat frame_gray;
//load image with a face on it
Mat frame = imread( "/home/w/Desktop/opencv-master/samples/cpp/lena.jpg", 1);
 
//Convert image to grayscale so its ready to use in detectMultiScale
cvtColor(frame, frame_gray, COLOR_BGR2GRAY);
//equalize image so its ready to use in detectMultiScale
equalizeHist(frame_gray, frame_gray);
 
// create size params for detectMultiScale
Size a = Size(30, 30);
Size b = Size();
 
// run face detector , the faces variable is set with 1 or more vector<Rect> by detectMultiScale, usually 0, 1, or 2
//I'm using my c wrapper for c++ detectMultiScale here to test it and it works as good as the the C++ function it wraps
 
cv_CascadeClassifier_detectMultiScale(&face_cascade, &frame_gray, &faces, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, &a,&b);
 
// Set Region of Interest
 
size_t ic = 0; // ic is index of current element
for (ic = 0; ic < faces.size(); ic++)
 
{// using my vector wrapper to convert the vector<Rect> output to a Rect*
Rect* c = std_vectorrToCArray(&faces);
//here I can access different elements of the array C, where in Lisp I cant.
In Lisp when I run (cffi:mem-aref (vector-rect-to-c-array C) ic) I get a memory fault error...cont. at bottom
cout << c[ic].x;
}}
here is my wrapper for std_vectorr_to_carray...I think its defined correctly
 
(defcfun ("std_vectorr_to_carray" %vector-rect-to-c-array) :pointer
(s (:pointer vector-rect)))
 
 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.