mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
Classifier uses C++ OpenCV cv::VideoCapture that hasn't bugs.
This commit is contained in:
@ -21,6 +21,8 @@
|
||||
#include "opencv2/videoio/videoio_c.h"
|
||||
#endif
|
||||
image get_image_from_stream(CvCapture *cap);
|
||||
image get_image_from_stream_cpp(CvCapture *cap);
|
||||
#include "http_stream.h"
|
||||
#endif
|
||||
|
||||
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);
|
||||
CvCapture * cap;
|
||||
|
||||
if(filename){
|
||||
cap = cvCaptureFromFile(filename);
|
||||
}else{
|
||||
cap = cvCaptureFromCAM(cam_index);
|
||||
}
|
||||
if (filename) {
|
||||
//cap = cvCaptureFromFile(filename);
|
||||
cap = get_capture_video_stream(filename);
|
||||
}
|
||||
else {
|
||||
//cap = cvCaptureFromCAM(cam_index);
|
||||
cap = get_capture_webcam(filename);
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
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);
|
||||
CvCapture * cap;
|
||||
|
||||
if(filename){
|
||||
cap = cvCaptureFromFile(filename);
|
||||
}else{
|
||||
cap = cvCaptureFromCAM(cam_index);
|
||||
}
|
||||
if (filename) {
|
||||
//cap = cvCaptureFromFile(filename);
|
||||
cap = get_capture_video_stream(filename);
|
||||
}
|
||||
else {
|
||||
//cap = cvCaptureFromCAM(cam_index);
|
||||
cap = get_capture_webcam(filename);
|
||||
}
|
||||
|
||||
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;
|
||||
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);
|
||||
show_image(in, "Threat Detection");
|
||||
|
||||
@ -1070,9 +1080,11 @@ void demo_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_ind
|
||||
CvCapture * cap;
|
||||
|
||||
if(filename){
|
||||
cap = cvCaptureFromFile(filename);
|
||||
//cap = cvCaptureFromFile(filename);
|
||||
cap = get_capture_video_stream(filename);
|
||||
}else{
|
||||
cap = cvCaptureFromCAM(cam_index);
|
||||
//cap = cvCaptureFromCAM(cam_index);
|
||||
cap = get_capture_webcam(filename);
|
||||
}
|
||||
|
||||
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;
|
||||
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);
|
||||
show_image(in, "Classifier");
|
||||
|
||||
|
22
src/image.c
22
src/image.c
@ -988,6 +988,28 @@ image get_image_from_stream(CvCapture *cap)
|
||||
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)
|
||||
{
|
||||
IplImage* src;
|
||||
|
Reference in New Issue
Block a user