Last active
January 22, 2020 14:50
-
-
Save joshuajnoble/c92b843edca6d89ee219 to your computer and use it in GitHub Desktop.
passing SVM to gpu::HOG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// might need to check | |
// http://stackoverflow.com/questions/15033363/obtaining-weights-in-cvsvm-the-svm-implementation-of-opencv/15070681#15070681 | |
// for more info on how to get the svm from the CvSVM object to pass to HOG | |
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <sstream> | |
#include <iomanip> | |
#include <stdexcept> | |
#include <opencv2/core/utility.hpp> | |
#include "opencv2/cuda.hpp" | |
#include "opencv2/highgui.hpp" | |
#include "opencv2/objdetect.hpp" | |
#include "opencv2/imgproc.hpp" | |
using namespace std; | |
using namespace cv; | |
int main() | |
{ | |
cv::cuda::printShortCudaDeviceInfo(cv::cuda::getDevice()); | |
Size win_size(args.win_width, args.win_width * 2); //(64, 128) or (48, 96) | |
Size win_stride(args.win_stride_width, args.win_stride_height); | |
vector<float> detector; | |
string filepath = "path/to/svm/file"; | |
CvSVM svm; | |
svm.load(filepath.c_str()); | |
cv::cuda::HOGDescriptor gpu_hog(win_size, Size(16, 16), Size(8, 8), Size(8, 8), 9, | |
cv::cuda::HOGDescriptor::DEFAULT_WIN_SIGMA, 0.2, gamma_corr, | |
cv::cuda::HOGDescriptor::DEFAULT_NLEVELS); | |
gpu_hog.setSVMDetector(svm.get_support_vector(0)); | |
cuda::GpuMat gpu_img; | |
while() | |
{ | |
gpu_img.upload(img); // assuming an img came from somewhere | |
gpu_hog.detectMultiScale(gpu_img, found, hit_threshold, win_stride, Size(0, 0), scale, gr_threshold); | |
for (size_t i = 0; i < found.size(); i++) | |
{ | |
Rect r = found[i]; | |
rectangle(img_to_show, r.tl(), r.br(), Scalar(0, 255, 0), 3); | |
} | |
putText(img_to_show, "Mode: GPU", Point(5, 25), FONT_HERSHEY_SIMPLEX, 1., Scalar(255, 100, 0), 2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment