mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
Fixed uses of WebCam for OpenCV 3.x
This commit is contained in:
@ -145,7 +145,7 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>C:\opencv_3.0\opencv\build\x64\vc14\lib;C:\opencv_2.4.13\opencv\build\x64\vc14\lib;$(CUDA_PATH)lib\$(PlatformName);$(cudnn)\lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalLibraryDirectories>C:\opencv_3.0\opencv\build\x64\vc14\lib;C:\opencv_2.4.13\opencv\build\x64\vc14\lib;C:\opencv_2.4.13\opencv\build\x64\vc12\lib;$(CUDA_PATH)lib\$(PlatformName);$(cudnn)\lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>..\..\3rdparty\lib\x64\pthreadVC2.lib;cublas.lib;curand.lib;cudart.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)\$(TargetName)$(TargetExt)</OutputFile>
|
||||
</Link>
|
||||
|
@ -176,47 +176,6 @@ void push_batchnorm_layer(layer l)
|
||||
cuda_push_array(l.rolling_mean_gpu, l.rolling_mean, l.c);
|
||||
cuda_push_array(l.rolling_variance_gpu, l.rolling_variance, l.c);
|
||||
}
|
||||
/*
|
||||
void forward_batchnorm_layer_gpu(layer l, network_state state)
|
||||
{
|
||||
if(l.type == BATCHNORM) copy_ongpu(l.outputs*l.batch, state.input, 1, l.output_gpu, 1);
|
||||
if(l.type == CONNECTED){
|
||||
l.out_c = l.outputs;
|
||||
l.out_h = l.out_w = 1;
|
||||
}
|
||||
if (state.train) {
|
||||
fast_mean_gpu(l.output_gpu, l.batch, l.out_c, l.out_h*l.out_w, l.mean_gpu);
|
||||
fast_variance_gpu(l.output_gpu, l.mean_gpu, l.batch, l.out_c, l.out_h*l.out_w, l.variance_gpu);
|
||||
|
||||
scal_ongpu(l.out_c, .99, l.rolling_mean_gpu, 1);
|
||||
axpy_ongpu(l.out_c, .01, l.mean_gpu, 1, l.rolling_mean_gpu, 1);
|
||||
scal_ongpu(l.out_c, .99, l.rolling_variance_gpu, 1);
|
||||
axpy_ongpu(l.out_c, .01, l.variance_gpu, 1, l.rolling_variance_gpu, 1);
|
||||
|
||||
copy_ongpu(l.outputs*l.batch, l.output_gpu, 1, l.x_gpu, 1);
|
||||
normalize_gpu(l.output_gpu, l.mean_gpu, l.variance_gpu, l.batch, l.out_c, l.out_h*l.out_w);
|
||||
copy_ongpu(l.outputs*l.batch, l.output_gpu, 1, l.x_norm_gpu, 1);
|
||||
} else {
|
||||
normalize_gpu(l.output_gpu, l.rolling_mean_gpu, l.rolling_variance_gpu, l.batch, l.out_c, l.out_h*l.out_w);
|
||||
}
|
||||
|
||||
scale_bias_gpu(l.output_gpu, l.scales_gpu, l.batch, l.out_c, l.out_h*l.out_w);
|
||||
}
|
||||
|
||||
void backward_batchnorm_layer_gpu(const layer l, network_state state)
|
||||
{
|
||||
backward_scale_gpu(l.x_norm_gpu, l.delta_gpu, l.batch, l.out_c, l.out_w*l.out_h, l.scale_updates_gpu);
|
||||
|
||||
scale_bias_gpu(l.delta_gpu, l.scales_gpu, l.batch, l.out_c, l.out_h*l.out_w);
|
||||
|
||||
fast_mean_delta_gpu(l.delta_gpu, l.variance_gpu, l.batch, l.out_c, l.out_w*l.out_h, l.mean_delta_gpu);
|
||||
fast_variance_delta_gpu(l.x_gpu, l.delta_gpu, l.mean_gpu, l.variance_gpu, l.batch, l.out_c, l.out_w*l.out_h, l.variance_delta_gpu);
|
||||
normalize_delta_gpu(l.x_gpu, l.mean_gpu, l.variance_gpu, l.mean_delta_gpu, l.variance_delta_gpu, l.batch, l.out_c, l.out_w*l.out_h, l.delta_gpu);
|
||||
if(l.type == BATCHNORM) copy_ongpu(l.outputs*l.batch, l.delta_gpu, 1, state.delta, 1);
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
|
||||
void forward_batchnorm_layer_gpu(layer l, network_state state)
|
||||
{
|
||||
|
10
src/demo.c
10
src/demo.c
@ -39,6 +39,7 @@ static image det ;
|
||||
static image det_s;
|
||||
static image disp = {0};
|
||||
static CvCapture * cap;
|
||||
static int use_webcam = 0;
|
||||
static float fps = 0;
|
||||
static float demo_thresh = 0;
|
||||
|
||||
@ -50,7 +51,7 @@ static float *avg;
|
||||
|
||||
void draw_detections_cv(IplImage* show_img, int num, float thresh, box *boxes, float **probs, char **names, image **alphabet, int classes);
|
||||
void show_image_cv_ipl(IplImage *disp, const char *name);
|
||||
image get_image_from_stream_resize(CvCapture *cap, int w, int h, IplImage** in_img);
|
||||
image get_image_from_stream_resize(CvCapture *cap, int w, int h, IplImage** in_img, int use_webcam);
|
||||
IplImage* in_img;
|
||||
IplImage* det_img;
|
||||
IplImage* show_img;
|
||||
@ -60,7 +61,7 @@ static int flag_exit;
|
||||
void *fetch_in_thread(void *ptr)
|
||||
{
|
||||
//in = get_image_from_stream(cap);
|
||||
in = get_image_from_stream_resize(cap, net.w, net.h, &in_img);
|
||||
in = get_image_from_stream_resize(cap, net.w, net.h, &in_img, use_webcam);
|
||||
if(!in.data){
|
||||
//error("Stream closed.");
|
||||
flag_exit = 1;
|
||||
@ -144,7 +145,12 @@ void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const ch
|
||||
cap = cvCaptureFromFile(filename);
|
||||
}else{
|
||||
printf("Webcam index: %d\n", cam_index);
|
||||
#ifdef CV_VERSION_EPOCH // OpenCV 2.x
|
||||
cap = cvCaptureFromCAM(cam_index);
|
||||
#else // OpenCV 3.x
|
||||
use_webcam = 1;
|
||||
cap = get_capture_webcam(cam_index);
|
||||
#endif
|
||||
}
|
||||
|
||||
if(!cap) error("Couldn't connect to webcam.\n");
|
||||
|
@ -195,4 +195,20 @@ void send_mjpeg(IplImage* ipl, int port, int timeout, int quality) {
|
||||
std::cout << " MJPEG-stream sent. \n";
|
||||
}
|
||||
|
||||
|
||||
CvCapture* get_capture_webcam(int index) {
|
||||
CvCapture* cap = (CvCapture*)new cv::VideoCapture(index);
|
||||
return cap;
|
||||
}
|
||||
|
||||
IplImage* get_webcam_frame(CvCapture *cap) {
|
||||
cv::VideoCapture &cpp_cap = *(cv::VideoCapture *)cap;
|
||||
cv::Mat frame;
|
||||
cpp_cap >> frame;
|
||||
IplImage* src = cvCreateImage(cvSize(frame.cols, frame.rows), 8, frame.channels());
|
||||
*src = frame;
|
||||
return src;
|
||||
}
|
||||
|
||||
|
||||
#endif // OPENCV
|
@ -7,6 +7,8 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
void send_mjpeg(IplImage* ipl, int port, int timeout, int quality);
|
||||
CvCapture* get_capture_webcam(int index);
|
||||
IplImage* get_webcam_frame(CvCapture *cap);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -14,12 +14,12 @@
|
||||
#include "opencv2/highgui/highgui_c.h"
|
||||
#include "opencv2/imgproc/imgproc_c.h"
|
||||
#include "opencv2/core/version.hpp"
|
||||
#include "http_stream.h"
|
||||
#ifndef CV_VERSION_EPOCH
|
||||
#include "opencv2/videoio/videoio_c.h"
|
||||
#include "opencv2/imgcodecs/imgcodecs_c.h"
|
||||
#include "http_stream.h"
|
||||
#endif
|
||||
#include "http_stream.h"
|
||||
#endif
|
||||
|
||||
int windows = 0;
|
||||
@ -683,9 +683,12 @@ image get_image_from_stream(CvCapture *cap)
|
||||
return im;
|
||||
}
|
||||
|
||||
image get_image_from_stream_resize(CvCapture *cap, int w, int h, IplImage** in_img)
|
||||
image get_image_from_stream_resize(CvCapture *cap, int w, int h, IplImage** in_img, int use_webcam)
|
||||
{
|
||||
IplImage* src = cvQueryFrame(cap);
|
||||
IplImage* src;
|
||||
if (use_webcam) src = get_webcam_frame(cap);
|
||||
else src = cvQueryFrame(cap);
|
||||
|
||||
if (!src) return make_empty_image(0, 0, 0);
|
||||
IplImage* new_img = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, 3);
|
||||
*in_img = cvCreateImage(cvSize(src->width, src->height), IPL_DEPTH_8U, 3);
|
||||
|
Reference in New Issue
Block a user