Classifier uses C++ OpenCV cv::VideoCapture that hasn't bugs.

pull/901/head^2
AlexeyAB 7 years ago
parent eef9f8e5bb
commit f52040f0bf
  1. 43
      src/classifier.c
  2. 22
      src/image.c

@ -21,6 +21,8 @@
#include "opencv2/videoio/videoio_c.h" #include "opencv2/videoio/videoio_c.h"
#endif #endif
image get_image_from_stream(CvCapture *cap); image get_image_from_stream(CvCapture *cap);
image get_image_from_stream_cpp(CvCapture *cap);
#include "http_stream.h"
#endif #endif
float *get_regression_values(char **labels, int n) float *get_regression_values(char **labels, int n)
@ -860,11 +862,14 @@ void threat_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_i
srand(2222222); srand(2222222);
CvCapture * cap; CvCapture * cap;
if(filename){ if (filename) {
cap = cvCaptureFromFile(filename); //cap = cvCaptureFromFile(filename);
}else{ cap = get_capture_video_stream(filename);
cap = cvCaptureFromCAM(cam_index); }
} else {
//cap = cvCaptureFromCAM(cam_index);
cap = get_capture_webcam(filename);
}
int top = option_find_int(options, "top", 1); int top = option_find_int(options, "top", 1);
@ -886,7 +891,8 @@ void threat_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_i
struct timeval tval_before, tval_after, tval_result; struct timeval tval_before, tval_after, tval_result;
gettimeofday(&tval_before, NULL); gettimeofday(&tval_before, NULL);
image in = get_image_from_stream(cap); //image in = get_image_from_stream(cap);
image in = get_image_from_stream_cpp(cap);
if(!in.data) break; if(!in.data) break;
image in_s = resize_image(in, net.w, net.h); image in_s = resize_image(in, net.w, net.h);
@ -992,11 +998,14 @@ void gun_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_inde
srand(2222222); srand(2222222);
CvCapture * cap; CvCapture * cap;
if(filename){ if (filename) {
cap = cvCaptureFromFile(filename); //cap = cvCaptureFromFile(filename);
}else{ cap = get_capture_video_stream(filename);
cap = cvCaptureFromCAM(cam_index); }
} else {
//cap = cvCaptureFromCAM(cam_index);
cap = get_capture_webcam(filename);
}
int top = option_find_int(options, "top", 1); int top = option_find_int(options, "top", 1);
@ -1015,7 +1024,8 @@ void gun_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_inde
struct timeval tval_before, tval_after, tval_result; struct timeval tval_before, tval_after, tval_result;
gettimeofday(&tval_before, NULL); gettimeofday(&tval_before, NULL);
image in = get_image_from_stream(cap); //image in = get_image_from_stream(cap);
image in = get_image_from_stream_cpp(cap);
image in_s = resize_image(in, net.w, net.h); image in_s = resize_image(in, net.w, net.h);
show_image(in, "Threat Detection"); show_image(in, "Threat Detection");
@ -1070,9 +1080,11 @@ void demo_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_ind
CvCapture * cap; CvCapture * cap;
if(filename){ if(filename){
cap = cvCaptureFromFile(filename); //cap = cvCaptureFromFile(filename);
cap = get_capture_video_stream(filename);
}else{ }else{
cap = cvCaptureFromCAM(cam_index); //cap = cvCaptureFromCAM(cam_index);
cap = get_capture_webcam(filename);
} }
int top = option_find_int(options, "top", 1); int top = option_find_int(options, "top", 1);
@ -1092,7 +1104,8 @@ void demo_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_ind
struct timeval tval_before, tval_after, tval_result; struct timeval tval_before, tval_after, tval_result;
gettimeofday(&tval_before, NULL); gettimeofday(&tval_before, NULL);
image in = get_image_from_stream(cap); //image in = get_image_from_stream(cap);
image in = get_image_from_stream_cpp(cap);
image in_s = resize_image(in, net.w, net.h); image in_s = resize_image(in, net.w, net.h);
show_image(in, "Classifier"); show_image(in, "Classifier");

@ -988,6 +988,28 @@ image get_image_from_stream(CvCapture *cap)
return im; return im;
} }
image get_image_from_stream_cpp(CvCapture *cap)
{
//IplImage* src = cvQueryFrame(cap);
IplImage* src;
static int once = 1;
if (once) {
once = 0;
do {
src = get_webcam_frame(cap);
if (!src) return make_empty_image(0, 0, 0);
} while (src->width < 1 || src->height < 1 || src->nChannels < 1);
printf("Video stream: %d x %d \n", src->width, src->height);
}
else
src = get_webcam_frame(cap);
if (!src) return make_empty_image(0, 0, 0);
image im = ipl_to_image(src);
rgbgr_image(im);
return im;
}
image get_image_from_stream_resize(CvCapture *cap, int w, int h, IplImage** in_img, int cpp_video_capture) image get_image_from_stream_resize(CvCapture *cap, int w, int h, IplImage** in_img, int cpp_video_capture)
{ {
IplImage* src; IplImage* src;

Loading…
Cancel
Save