16 static char **demo_names;
17 static image **demo_alphabet;
18 static int demo_classes;
21 static image buff [3];
22 static image buff_letter[3];
23 static int buff_index = 0;
24 static CvCapture * cap;
25 static IplImage * ipl;
27 static float demo_thresh = 0;
28 static float demo_hier = .5;
29 static int running = 0;
31 static int demo_frame = 3;
32 static int demo_index = 0;
33 static float **predictions;
35 static int demo_done = 0;
36 static int demo_total = 0;
45 for(i = 0; i < net->
n; ++i){
54 void remember_network(
network *net)
58 for(i = 0; i < net->
n; ++i){
72 for(j = 0; j < demo_frame; ++j){
73 axpy_cpu(demo_total, 1./demo_frame, predictions[j], 1, avg, 1);
75 for(i = 0; i < net->
n; ++i){
86 void *detect_in_thread(
void *ptr)
92 float *X = buff_letter[(buff_index+2)%3].
data;
99 remember_network(net);
102 dets = avg_predictions(net, &nboxes);
130 printf(
"\nFPS:%.1f\n",fps);
131 printf(
"Objects:\n\n");
132 image display = buff[(buff_index+2) % 3];
133 draw_detections(display, dets, nboxes, demo_thresh, demo_names, demo_alphabet, demo_classes);
136 demo_index = (demo_index + 1)%demo_frame;
141 void *fetch_in_thread(
void *ptr)
143 int status = fill_image_from_stream(cap, buff[buff_index]);
145 if(status == 0) demo_done = 1;
149 void *display_in_thread(
void *ptr)
151 show_image_cv(buff[(buff_index + 1)%3],
"Demo", ipl);
152 int c = cvWaitKey(1);
153 if (c != -1) c = c%256;
157 }
else if (c == 82) {
159 }
else if (c == 84) {
161 if(demo_thresh <= .02) demo_thresh = .02;
162 }
else if (c == 83) {
164 }
else if (c == 81) {
166 if(demo_hier <= .0) demo_hier = .0;
171 void *display_loop(
void *ptr)
174 display_in_thread(0);
178 void *detect_loop(
void *ptr)
185 void demo(
char *cfgfile,
char *weightfile,
float thresh,
int cam_index,
const char *filename,
char **names,
int classes,
int delay,
char *prefix,
int avg_frames,
float hier,
int w,
int h,
int frames,
int fullscreen)
190 demo_alphabet = alphabet;
192 demo_thresh = thresh;
197 pthread_t detect_thread;
198 pthread_t fetch_thread;
203 demo_total = size_network(net);
204 predictions = calloc(demo_frame,
sizeof(
float*));
205 for (i = 0; i < demo_frame; ++i){
206 predictions[i] = calloc(demo_total,
sizeof(
float));
208 avg = calloc(demo_total,
sizeof(
float));
211 printf(
"video file: %s\n", filename);
212 cap = cvCaptureFromFile(filename);
214 cap = cvCaptureFromCAM(cam_index);
217 cvSetCaptureProperty(cap, CV_CAP_PROP_FRAME_WIDTH, w);
220 cvSetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT, h);
223 cvSetCaptureProperty(cap, CV_CAP_PROP_FPS, frames);
227 if(!cap)
error(
"Couldn't connect to webcam.\n");
229 buff[0] = get_image_from_stream(cap);
235 ipl = cvCreateImage(cvSize(buff[0].w,buff[0].h), IPL_DEPTH_8U, buff[0].c);
239 cvNamedWindow(
"Demo", CV_WINDOW_NORMAL);
241 cvSetWindowProperty(
"Demo", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
243 cvMoveWindow(
"Demo", 0, 0);
244 cvResizeWindow(
"Demo", 1352, 1013);
251 buff_index = (buff_index + 1) %3;
252 if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0))
error(
"Thread creation failed");
253 if(pthread_create(&detect_thread, 0, detect_in_thread, 0))
error(
"Thread creation failed");
257 display_in_thread(0);
260 sprintf(name,
"%s_%08d", prefix, count);
263 pthread_join(fetch_thread, 0);
264 pthread_join(detect_thread, 0);
359 void demo(
char *cfgfile,
char *weightfile,
float thresh,
int cam_index,
const char *filename,
char **names,
int classes,
int delay,
char *prefix,
int avg,
float hier,
int w,
int h,
int frames,
int fullscreen)
361 fprintf(stderr,
"Demo needs OpenCV for webcam images.\n");
image copy_image(image p)
void set_batch_network(network *net, int b)
void save_image(image p, const char *name)
void fill_cpu(int N, float ALPHA, float *X, int INCX)
void axpy_cpu(int N, float ALPHA, float *X, int INCX, float *Y, int INCY)
void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int delay, char *prefix, int avg, float hier, int w, int h, int frames, int fullscreen)
network * load_network(char *cfg, char *weights, int clear)
void letterbox_image_into(image im, int w, int h, image boxed)
void draw_detections(image im, detection *dets, int num, float thresh, char **names, image **alphabet, int classes)
void error(const char *s)
double what_time_is_it_now()