Skip to content

Instantly share code, notes, and snippets.

@stephanschulz
Created April 25, 2016 17:36
Show Gist options
  • Save stephanschulz/9719fe9bfbcb6cc2e14296f9cf34464d to your computer and use it in GitHub Desktop.
Save stephanschulz/9719fe9bfbcb6cc2e14296f9cf34464d to your computer and use it in GitHub Desktop.
OF 0.9.3 gpu opencv
#include "ofApp.h"
int main() {
ofSetupOpenGL(640, 480, OF_WINDOW);
ofRunApp(new ofApp());
}
#include "ofApp.h"
using namespace ofxCv;
using namespace cv;
void ofApp::setup() {
cam.setup(320, 240);
imitate(img, cam);
// Mat img(imread("frame_7.png", CV_LOAD_IMAGE_GRAYSCALE), cv::Rect(130, 80, 64, 128));
}
void ofApp::update() {
cam.update();
if(cam.isFrameNew()) {
copy(cam,img);
img.update();
gpu::GpuMat gpu_img;
gpu_img.upload(toCv(img));
//initialize detector and HOGDescriptor
vector<float> detector = HOGDescriptor::getDefaultPeopleDetector();
gpu::HOGDescriptor gpu_hog(cv::Size(64, 128), cv::Size(16, 16), cv::Size(8, 8), cv::Size(8, 8),9);
HOGDescriptor cpu_hog(cv::Size(64, 128), cv::Size(16, 16), cv::Size(8, 8), cv::Size(8, 8), 9);
gpu_hog.setSVMDetector(detector);
cpu_hog.setSVMDetector(detector);
//get descriptor vector -- cpu
vector<float> cpu_descriptor, gpu_descriptor_vec;
cpu_hog.compute(gpu_img, cpu_descriptor, cv::Size(8, 8), cv::Size(0, 0));
//get descriptor vector -- gpu
gpu::GpuMat gpu_descriptor_temp;
gpu_hog.getDescriptors(gpu_img, cv::Size(8, 8), gpu_descriptor_temp);
Mat gpu_descriptor(gpu_descriptor_temp);
gpu_descriptor.copyTo(gpu_descriptor_vec);
//compare cpu_descriptor <--> gpu_descriptor
for(int i=0;i<cpu_descriptor.size();i++){
cout << i << " : " << cpu_descriptor[i] << " <--> " << gpu_descriptor_vec[i] << endl;
}
}
}
void ofApp::draw() {
ofSetColor(255);
img.draw(0, 0);
}
#pragma once
#include "ofMain.h"
#include "ofxCv.h"
#include "ofxOpenCv.h"
class ofApp : public ofBaseApp {
public:
void setup();
void update();
void draw();
ofVideoGrabber cam;
ofImage img;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment