pull/1106/head
AlexeyAB 7 years ago
parent 17520296c7
commit 22796c5a49
  1. 6
      src/darknet.c
  2. 15
      src/demo.c
  3. 3
      src/detector.c
  4. 38
      src/image.c

@ -354,6 +354,12 @@ int main(int argc, char **argv)
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
int i;
for (i = 0; i < argc; ++i) {
if (!argv[i]) continue;
strip(argv[i]);
}
//test_resize("data/bad.jpg");
//test_box();
//test_convolutional_layer();

@ -87,16 +87,7 @@ void *detect_in_thread(void *ptr)
l.output = avg;
free_image(det_s);
/*
if(l.type == DETECTION){
get_detection_boxes(l, 1, 1, demo_thresh, probs, boxes, 0);
} else if (l.type == REGION){
get_region_boxes(l, 1, 1, demo_thresh, probs, boxes, 0, 0);
} else {
error("Last layer must produce detections\n");
}
if (nms > 0) do_nms(boxes, probs, l.w*l.h*l.n, l.classes, nms);
*/
int letter = 0;
int nboxes = 0;
detection *dets = get_network_boxes(&net, det_s.w, det_s.h, demo_thresh, demo_thresh, 0, 1, &nboxes, letter);
@ -109,15 +100,11 @@ void *detect_in_thread(void *ptr)
printf("\nFPS:%.1f\n",fps);
printf("Objects:\n\n");
//images[demo_index] = det;
//det = images[(demo_index + FRAMES/2 + 1)%FRAMES];
ipl_images[demo_index] = det_img;
det_img = ipl_images[(demo_index + FRAMES / 2 + 1) % FRAMES];
demo_index = (demo_index + 1)%FRAMES;
//draw_detections(det, l.w*l.h*l.n, demo_thresh, boxes, probs, demo_names, demo_alphabet, demo_classes);
draw_detections_cv_v3(det_img, dets, nboxes, demo_thresh, demo_names, demo_alphabet, demo_classes, demo_ext_output);
//draw_detections_cv(det_img, l.w*l.h*l.n, demo_thresh, boxes, probs, demo_names, demo_alphabet, demo_classes);
free_detections(dets, nboxes);
return 0;

@ -976,6 +976,7 @@ void calc_anchors(char *datacfg, int num_of_clusters, int width, int height, int
//for (i = 0; i < number_of_boxes; ++i)
// printf("%2.2f,%2.2f, ", points->data.fl[i * 2], points->data.fl[i * 2 + 1]);
printf("\n");
float avg_iou = 0;
for (i = 0; i < number_of_boxes; ++i) {
float box_w = points->data.fl[i * 2];
@ -999,7 +1000,7 @@ void calc_anchors(char *datacfg, int num_of_clusters, int width, int height, int
float box_intersect = min_w*min_h;
float box_union = box_w*box_h + anchor_w*anchor_h - box_intersect;
float iou = box_intersect / box_union;
if (iou > 1 || iou < 0) {
if (iou > 1 || iou < 0 || box_w > width || box_h > height) {
printf(" i = %d, box_w = %d, box_h = %d, anchor_w = %d, anchor_h = %d, iou = %f \n",
i, box_w, box_h, anchor_w, anchor_h, iou);
}

@ -1011,6 +1011,26 @@ image get_image_from_stream_cpp(CvCapture *cap)
return im;
}
int wait_for_stream(CvCapture *cap, IplImage* src, int dont_close) {
if (!src) {
if (dont_close) src = cvCreateImage(cvSize(416, 416), IPL_DEPTH_8U, 3);
else return 0;
}
if (src->width < 1 || src->height < 1 || src->nChannels < 1) {
if (dont_close) {
cvReleaseImage(&src);
int z = 0;
for (z = 0; z < 20; ++z) {
get_webcam_frame(cap);
cvReleaseImage(&src);
}
src = cvCreateImage(cvSize(416, 416), IPL_DEPTH_8U, 3);
}
else return 0;
}
return 1;
}
image get_image_from_stream_resize(CvCapture *cap, int w, int h, int c, IplImage** in_img, int cpp_video_capture, int dont_close)
{
c = c ? c : 3;
@ -1029,22 +1049,8 @@ image get_image_from_stream_resize(CvCapture *cap, int w, int h, int c, IplImage
}
else src = cvQueryFrame(cap);
if (!src) {
if (dont_close) src = cvCreateImage(cvSize(416, 416), IPL_DEPTH_8U, c);
else return make_empty_image(0, 0, 0);
}
if (src->width < 1 || src->height < 1 || src->nChannels < 1) {
if (cpp_video_capture) {
cvReleaseImage(&src);
int z = 0;
for (z = 0; z < 10; ++z) {
get_webcam_frame(cap);
cvReleaseImage(&src);
}
}
if (dont_close) src = cvCreateImage(cvSize(416, 416), IPL_DEPTH_8U, c);
else return make_empty_image(0, 0, 0);
}
if (cpp_video_capture)
if(!wait_for_stream(cap, src, dont_close)) return make_empty_image(0, 0, 0);
IplImage* new_img = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, c);
*in_img = cvCreateImage(cvSize(src->width, src->height), IPL_DEPTH_8U, c);
cvResize(src, *in_img, CV_INTER_LINEAR);

Loading…
Cancel
Save