GPU Face Detection Error
I need help with an error in my simple GPU face detection program. The CPU version of this code runs fine with the same CascadeClassifier. This program is running on a NVIDIA TX2.
Error: OpenCV Error: Unspecified error (The node does not represent a user object (unknown type?)) in cvRead, file /hdd/buildbot/slave_jetson_tx_3/35-O4T-L4T-R24/opencv/modules/core/src/persistence.cpp, line 5008 terminate called after throwing an instance of 'cv::Exception' what(): /hdd/buildbot/slave_jetson_tx_3/35-O4T-L4T-R24/opencv/modules/core/src/persistence.cpp:5008: error: (-2) The node does not represent a user object (unknown type?) in function cvRead
Code :
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include<opencv2/highgui/highgui.hpp>
#include <opencv2/gpu/gpu.hpp>
#include <opencv2/gpu/gpumat.hpp>
#include <stdlib.h>
#include <chrono>
#include <iostream>
int main()
{
using std::chrono::duration_cast;
using std::chrono::nanoseconds;
typedef std::chrono::high_resolution_clock clock;
cv::Mat img = cv::imread("lena.tiff",CV_LOAD_IMAGE_GRAYSCALE);
cv::equalizeHist(img,img);
auto start = clock::now();
cv::gpu::GpuMat image_gpu(img);
cv::gpu::CascadeClassifier_GPU face_detector_gpu("/usr/share/OpenCV/haarcascades/haarcascade_frontalface_default.xml");
cv::gpu::GpuMat objbuf;
int detections = face_detector_gpu.detectMultiScale(image_gpu, objbuf);
cv::Mat obj_host;
objbuf.colRange(0,detections).download(obj_host);
cv::Rect* gpu_faces = obj_host.ptr<cv::Rect>();
for (int i=0;i<detections;i++)
cv::rectangle(img,gpu_faces[i],cv::Scalar(255));
auto end = clock::now();
std::cout << duration_cast<nanoseconds>(end-start).count()/1000000 << "ms\n";
cv::imshow("img",img);
cv::waitKey();
return 0;
}
Compiled with: g++ -std=c++11 main.cpp -I/usr/include -lopencv_core -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_objdetect -o main