Some C OpenCV functions replaced by CPP functions

pull/2897/head
AlexeyAB 6 years ago
parent d7a95aefb2
commit 79c669707c
  1. 2
      src/art.c
  2. 2
      src/classifier.c
  3. 9
      src/demo.c
  4. 267
      src/image_opencv.cpp
  5. 17
      src/image_opencv.h
  6. 2
      src/rnn_vid.c
  7. 4
      src/voxel.c

@ -34,7 +34,7 @@ void demo_art(char *cfgfile, char *weightfile, int cam_index)
int n = sizeof(idx)/sizeof(idx[0]); int n = sizeof(idx)/sizeof(idx[0]);
while(1){ while(1){
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, window); show_image(in, window);

@ -1171,10 +1171,8 @@ void demo_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_ind
cap_cv * cap; cap_cv * cap;
if(filename){ if(filename){
//cap = cvCaptureFromFile(filename);
cap = get_capture_video_stream(filename); cap = get_capture_video_stream(filename);
}else{ }else{
//cap = cvCaptureFromCAM(cam_index);
cap = get_capture_webcam(cam_index); cap = get_capture_webcam(cam_index);
} }

@ -31,7 +31,6 @@ static image in_s ;
static image det_s; static image det_s;
static cap_cv *cap; static cap_cv *cap;
static int cpp_video_capture = 0;
static float fps = 0; static float fps = 0;
static float demo_thresh = 0; static float demo_thresh = 0;
static int demo_ext_output = 0; static int demo_ext_output = 0;
@ -55,9 +54,9 @@ void *fetch_in_thread(void *ptr)
{ {
int dont_close_stream = 0; // set 1 if your IP-camera periodically turns off and turns on video-stream int dont_close_stream = 0; // set 1 if your IP-camera periodically turns off and turns on video-stream
if(letter_box) if(letter_box)
in_s = get_image_from_stream_letterbox(cap, net.w, net.h, net.c, &in_img, cpp_video_capture, dont_close_stream); in_s = get_image_from_stream_letterbox(cap, net.w, net.h, net.c, &in_img, dont_close_stream);
else else
in_s = get_image_from_stream_resize(cap, net.w, net.h, net.c, &in_img, cpp_video_capture, dont_close_stream); in_s = get_image_from_stream_resize(cap, net.w, net.h, net.c, &in_img, dont_close_stream);
if(!in_s.data){ if(!in_s.data){
printf("Stream closed.\n"); printf("Stream closed.\n");
flag_exit = 1; flag_exit = 1;
@ -126,11 +125,9 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
if(filename){ if(filename){
printf("video file: %s\n", filename); printf("video file: %s\n", filename);
cpp_video_capture = 1;
cap = get_capture_video_stream(filename); cap = get_capture_video_stream(filename);
}else{ }else{
printf("Webcam index: %d\n", cam_index); printf("Webcam index: %d\n", cam_index);
cpp_video_capture = 1;
cap = get_capture_webcam(cam_index); cap = get_capture_webcam(cam_index);
} }
@ -187,7 +184,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
if (out_filename && !flag_exit) if (out_filename && !flag_exit)
{ {
int src_fps = 25; int src_fps = 25;
src_fps = get_stream_fps(cap, cpp_video_capture); src_fps = get_stream_fps_cpp_cv(cap);
output_video_writer = output_video_writer =
create_video_writer(out_filename, 'D', 'I', 'V', 'X', src_fps, get_width_cv(det_img), get_height_cv(det_img), 1); create_video_writer(out_filename, 'D', 'I', 'V', 'X', src_fps, get_width_cv(det_img), get_height_cv(det_img), 1);

@ -1,13 +1,21 @@
#ifdef OPENCV
#include "image_opencv.h" #include "image_opencv.h"
#ifdef OPENCV
#include "utils.h" #include "utils.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include "opencv2/opencv.hpp" #include <opencv2/world.hpp>
#include <opencv2/core/version.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/opencv_modules.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/imgcodecs.hpp>
using namespace cv; using namespace cv;
@ -37,8 +45,8 @@ using std::endl;
#ifndef CV_VERSION_EPOCH #ifndef CV_VERSION_EPOCH
#include <opencv2/videoio/videoio_c.h> #include <opencv2/videoio/videoio_c.h>
#include <opencv2/imgcodecs/imgcodecs_c.h> #include <opencv2/imgcodecs/imgcodecs_c.h>
#include "http_stream.h"
#endif #endif
#include "http_stream.h" #include "http_stream.h"
#ifndef CV_RGB #ifndef CV_RGB
@ -48,8 +56,8 @@ using std::endl;
extern "C" { extern "C" {
struct mat_cv :IplImage { int a[0]; }; struct mat_cv :IplImage { int a[0]; };
//struct cap_cv : CvCapture { int a[0]; }; struct cap_cv : cv::VideoCapture { int a[0]; };
//struct write_cv : CvVideoWriter { int a[0]; }; struct write_cv : cv::VideoWriter { int a[0]; };
// ==================================================================== // ====================================================================
// cv::Mat / IplImage // cv::Mat / IplImage
@ -197,6 +205,12 @@ image ipl_to_image_custom(mat_cv* src)
} }
// ---------------------------------------- // ----------------------------------------
cv::Mat ipl_to_mat(IplImage *ipl)
{
Mat m = cvarrToMat(ipl, true);
return m;
}
Mat image_to_mat(image im) Mat image_to_mat(image im)
{ {
image copy = copy_image(im); image copy = copy_image(im);
@ -224,24 +238,24 @@ image mat_to_image(Mat m)
// ==================================================================== // ====================================================================
void create_window_cv(char const* window_name, int full_screen, int width, int height) void create_window_cv(char const* window_name, int full_screen, int width, int height)
{ {
int window_type = CV_WINDOW_NORMAL; int window_type = WINDOW_NORMAL;
if (full_screen) window_type = CV_WINDOW_FULLSCREEN; if (full_screen) window_type = WINDOW_FULLSCREEN;
cvNamedWindow(window_name, window_type); cv::namedWindow(window_name, window_type);
cvMoveWindow(window_name, 0, 0); cv::moveWindow(window_name, 0, 0);
cvResizeWindow(window_name, width, height); cv::resizeWindow(window_name, width, height);
} }
// ---------------------------------------- // ----------------------------------------
void destroy_all_windows_cv() void destroy_all_windows_cv()
{ {
cvDestroyAllWindows(); cv::destroyAllWindows();
} }
// ---------------------------------------- // ----------------------------------------
int wait_key_cv(int delay) int wait_key_cv(int delay)
{ {
return cvWaitKey(delay); return cv::waitKey(delay);
} }
// ---------------------------------------- // ----------------------------------------
@ -253,13 +267,13 @@ int wait_until_press_key_cv()
void make_window(char *name, int w, int h, int fullscreen) void make_window(char *name, int w, int h, int fullscreen)
{ {
namedWindow(name, WINDOW_NORMAL); cv::namedWindow(name, WINDOW_NORMAL);
if (fullscreen) { if (fullscreen) {
setWindowProperty(name, CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN); cv::setWindowProperty(name, WND_PROP_FULLSCREEN, WINDOW_FULLSCREEN);
} }
else { else {
resizeWindow(name, w, h); cv::resizeWindow(name, w, h);
if (strcmp(name, "Demo") == 0) moveWindow(name, 0, 0); if (strcmp(name, "Demo") == 0) cv::moveWindow(name, 0, 0);
} }
} }
// ---------------------------------------- // ----------------------------------------
@ -320,7 +334,7 @@ void show_image_cv_ipl(mat_cv *disp, const char *name)
char buff[256]; char buff[256];
//sprintf(buff, "%s (%d)", name, windows); //sprintf(buff, "%s (%d)", name, windows);
sprintf(buff, "%s", name); sprintf(buff, "%s", name);
cvNamedWindow(buff, CV_WINDOW_NORMAL); cv::namedWindow(buff, WINDOW_NORMAL);
//cvMoveWindow(buff, 100*(windows%10) + 200*(windows/10), 100*(windows%10)); //cvMoveWindow(buff, 100*(windows%10) + 200*(windows/10), 100*(windows%10));
//++windows; //++windows;
cvShowImage(buff, disp); cvShowImage(buff, disp);
@ -333,20 +347,47 @@ void show_image_cv_ipl(mat_cv *disp, const char *name)
// ==================================================================== // ====================================================================
write_cv *create_video_writer(char *out_filename, char c1, char c2, char c3, char c4, int fps, int width, int height, int is_color) write_cv *create_video_writer(char *out_filename, char c1, char c2, char c3, char c4, int fps, int width, int height, int is_color)
{ {
CvVideoWriter * output_video_writer = try {
cvCreateVideoWriter(out_filename, CV_FOURCC(c1, c2, c3, c4), fps, cvSize(width, height), is_color); cv::VideoWriter * output_video_writer =
new cv::VideoWriter(out_filename, CV_FOURCC(c1, c2, c3, c4), fps, cv::Size(width, height), is_color);
return (write_cv *)output_video_writer; return (write_cv *)output_video_writer;
} }
catch (...) {
cerr << "OpenCV exception: create_video_writer \n";
}
return NULL;
}
int write_frame_cv(write_cv *output_video_writer, mat_cv *show_img) void write_frame_cv(write_cv *output_video_writer, mat_cv *show_img)
{ {
return cvWriteFrame((CvVideoWriter *)output_video_writer, show_img); try {
cv::VideoWriter *out = (cv::VideoWriter *)output_video_writer;
out->write(ipl_to_mat(show_img));
}
catch (...) {
cerr << "OpenCV exception: write_frame_cv \n";
}
} }
void release_video_writer(write_cv **output_video_writer) void release_video_writer(write_cv **output_video_writer)
{ {
cvReleaseVideoWriter((CvVideoWriter **)output_video_writer); try {
if (output_video_writer) {
std::cout << " closing...";
cv::VideoWriter *out = *(cv::VideoWriter **)output_video_writer;
out->release();
delete out;
output_video_writer = NULL;
std::cout << " closed!";
}
else {
cerr << "OpenCV exception: output_video_writer isn't created \n";
}
}
catch (...) {
cerr << "OpenCV exception: release_video_writer \n";
}
} }
/* /*
@ -390,12 +431,12 @@ int show_image_cv(image im, const char* name, int ms)
// ==================================================================== // ====================================================================
cap_cv* get_capture_video_stream(const char *path) { cap_cv* get_capture_video_stream(const char *path) {
CvCapture* cap = NULL; cv::VideoCapture* cap = NULL;
try { try {
cap = (CvCapture*)new cv::VideoCapture(path); cap = new cv::VideoCapture(path);
} }
catch (...) { catch (...) {
cerr << " Error: video-stream " << path << " can't be opened! \n"; cerr << " OpenCV exception: video-stream " << path << " can't be opened! \n";
} }
return (cap_cv*)cap; return (cap_cv*)cap;
} }
@ -403,14 +444,14 @@ cap_cv* get_capture_video_stream(const char *path) {
cap_cv* get_capture_webcam(int index) cap_cv* get_capture_webcam(int index)
{ {
CvCapture* cap = NULL; cv::VideoCapture* cap = NULL;
try { try {
cap = (CvCapture*)new cv::VideoCapture(index); cap = new cv::VideoCapture(index);
//((cv::VideoCapture*)cap)->set(CV_CAP_PROP_FRAME_WIDTH, 1280); //cap->set(CV_CAP_PROP_FRAME_WIDTH, 1280);
//((cv::VideoCapture*)cap)->set(CV_CAP_PROP_FRAME_HEIGHT, 960); //cap->set(CV_CAP_PROP_FRAME_HEIGHT, 960);
} }
catch (...) { catch (...) {
cerr << " Error: Web-camera " << index << " can't be opened! \n"; cerr << " OpenCV exception: Web-camera " << index << " can't be opened! \n";
} }
return (cap_cv*)cap; return (cap_cv*)cap;
} }
@ -423,7 +464,7 @@ void release_capture(cap_cv* cap)
delete cpp_cap; delete cpp_cap;
} }
catch (...) { catch (...) {
cerr << " Error: cv::VideoCapture " << cap << " can't be released! \n"; cerr << " OpenCV exception: cv::VideoCapture " << cap << " can't be released! \n";
} }
} }
// ---------------------------------------- // ----------------------------------------
@ -431,6 +472,7 @@ void release_capture(cap_cv* cap)
mat_cv* get_capture_frame_cv(cap_cv *cap) { mat_cv* get_capture_frame_cv(cap_cv *cap) {
IplImage* src = NULL; IplImage* src = NULL;
try { try {
if (cap) {
cv::VideoCapture &cpp_cap = *(cv::VideoCapture *)cap; cv::VideoCapture &cpp_cap = *(cv::VideoCapture *)cap;
cv::Mat frame; cv::Mat frame;
if (cpp_cap.isOpened()) if (cpp_cap.isOpened())
@ -439,12 +481,12 @@ mat_cv* get_capture_frame_cv(cap_cv *cap) {
IplImage tmp = frame; IplImage tmp = frame;
src = cvCloneImage(&tmp); src = cvCloneImage(&tmp);
} }
else { else std::cout << " Video-stream stopped! \n";
std::cout << " Video-stream stopped! \n";
} }
else cerr << " cv::VideoCapture isn't created \n";
} }
catch (...) { catch (...) {
std::cout << " Video-stream stoped! \n"; std::cout << " OpenCV exception: Video-stream stoped! \n";
} }
return (mat_cv *)src; return (mat_cv *)src;
} }
@ -475,7 +517,7 @@ double get_capture_property_cv(cap_cv *cap, int property_id)
return cpp_cap.get(property_id); return cpp_cap.get(property_id);
} }
catch (...) { catch (...) {
cerr << " Can't get property of source video-stream. \n"; cerr << " OpenCV exception: Can't get property of source video-stream. \n";
} }
return 0; return 0;
} }
@ -492,7 +534,7 @@ double get_capture_frame_count_cv(cap_cv *cap)
#endif #endif
} }
catch (...) { catch (...) {
cerr << " Can't get CAP_PROP_FRAME_COUNT of source videofile. \n"; cerr << " OpenCV exception: Can't get CAP_PROP_FRAME_COUNT of source videofile. \n";
} }
return 0; return 0;
} }
@ -528,50 +570,26 @@ int set_capture_position_frame_cv(cap_cv *cap, int index)
} }
// ---------------------------------------- // ----------------------------------------
// only for using in image_opencv.cpp
mat_cv* get_capture_frame(CvCapture *cap)
{
return get_capture_frame_cv((cap_cv *)cap);
}
// ----------------------------------------
// only for using in image_opencv.cpp
int get_stream_fps_cpp(CvCapture *cap)
{
return get_stream_fps_cpp_cv((cap_cv *)cap);
}
// ==================================================================== // ====================================================================
// ... Video Capture // ... Video Capture
// ==================================================================== // ====================================================================
image get_image_from_stream(cap_cv *cap_src)
{
CvCapture *cap = (CvCapture *)cap_src;
IplImage* src = cvQueryFrame(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_cpp(cap_cv *cap_src) image get_image_from_stream_cpp(cap_cv *cap)
{ {
CvCapture *cap = (CvCapture *)cap_src;
//IplImage* src = cvQueryFrame(cap);
IplImage* src; IplImage* src;
static int once = 1; static int once = 1;
if (once) { if (once) {
once = 0; once = 0;
do { do {
src = get_capture_frame(cap); src = get_capture_frame_cv(cap);
if (!src) return make_empty_image(0, 0, 0); if (!src) return make_empty_image(0, 0, 0);
} while (src->width < 1 || src->height < 1 || src->nChannels < 1); } while (src->width < 1 || src->height < 1 || src->nChannels < 1);
printf("Video stream: %d x %d \n", src->width, src->height); printf("Video stream: %d x %d \n", src->width, src->height);
} }
else else
src = get_capture_frame(cap); src = get_capture_frame_cv(cap);
if (!src) return make_empty_image(0, 0, 0); if (!src) return make_empty_image(0, 0, 0);
image im = ipl_to_image(src); image im = ipl_to_image(src);
@ -580,7 +598,7 @@ image get_image_from_stream_cpp(cap_cv *cap_src)
} }
// ---------------------------------------- // ----------------------------------------
int wait_for_stream(CvCapture *cap, IplImage* src, int dont_close) int wait_for_stream(cap_cv *cap, IplImage* src, int dont_close)
{ {
if (!src) { if (!src) {
if (dont_close) src = cvCreateImage(cvSize(416, 416), IPL_DEPTH_8U, 3); if (dont_close) src = cvCreateImage(cvSize(416, 416), IPL_DEPTH_8U, 3);
@ -591,7 +609,7 @@ int wait_for_stream(CvCapture *cap, IplImage* src, int dont_close)
cvReleaseImage(&src); cvReleaseImage(&src);
int z = 0; int z = 0;
for (z = 0; z < 20; ++z) { for (z = 0; z < 20; ++z) {
get_capture_frame(cap); get_capture_frame_cv(cap);
cvReleaseImage(&src); cvReleaseImage(&src);
} }
src = cvCreateImage(cvSize(416, 416), IPL_DEPTH_8U, 3); src = cvCreateImage(cvSize(416, 416), IPL_DEPTH_8U, 3);
@ -602,27 +620,23 @@ int wait_for_stream(CvCapture *cap, IplImage* src, int dont_close)
} }
// ---------------------------------------- // ----------------------------------------
image get_image_from_stream_resize(cap_cv *cap_src, int w, int h, int c, mat_cv** in_img, int cpp_video_capture, int dont_close) image get_image_from_stream_resize(cap_cv *cap, int w, int h, int c, mat_cv** in_img, int dont_close)
{ {
CvCapture *cap = (CvCapture *)cap_src;
c = c ? c : 3; c = c ? c : 3;
IplImage* src; IplImage* src;
if (cpp_video_capture) {
static int once = 1; static int once = 1;
if (once) { if (once) {
once = 0; once = 0;
do { do {
src = get_capture_frame(cap); src = get_capture_frame_cv(cap);
if (!src) return make_empty_image(0, 0, 0); if (!src) return make_empty_image(0, 0, 0);
} while (src->width < 1 || src->height < 1 || src->nChannels < 1); } while (src->width < 1 || src->height < 1 || src->nChannels < 1);
printf("Video stream: %d x %d \n", src->width, src->height); printf("Video stream: %d x %d \n", src->width, src->height);
} }
else else
src = get_capture_frame(cap); src = get_capture_frame_cv(cap);
}
else src = cvQueryFrame(cap);
if (cpp_video_capture)
if (!wait_for_stream(cap, src, dont_close)) return make_empty_image(0, 0, 0); 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); IplImage* new_img = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, c);
*in_img = (mat_cv *)cvCreateImage(cvSize(src->width, src->height), IPL_DEPTH_8U, c); *in_img = (mat_cv *)cvCreateImage(cvSize(src->width, src->height), IPL_DEPTH_8U, c);
@ -630,61 +644,41 @@ image get_image_from_stream_resize(cap_cv *cap_src, int w, int h, int c, mat_cv*
cvResize(src, new_img, CV_INTER_LINEAR); cvResize(src, new_img, CV_INTER_LINEAR);
image im = ipl_to_image(new_img); image im = ipl_to_image(new_img);
cvReleaseImage(&new_img); cvReleaseImage(&new_img);
if (cpp_video_capture) cvReleaseImage(&src); cvReleaseImage(&src);
if (c>1) if (c>1)
rgbgr_image(im); rgbgr_image(im);
return im; return im;
} }
// ---------------------------------------- // ----------------------------------------
image get_image_from_stream_letterbox(cap_cv *cap_src, int w, int h, int c, mat_cv** in_img, int cpp_video_capture, int dont_close) image get_image_from_stream_letterbox(cap_cv *cap, int w, int h, int c, mat_cv** in_img, int dont_close)
{ {
CvCapture *cap = (CvCapture *)cap_src;
c = c ? c : 3; c = c ? c : 3;
IplImage* src; IplImage* src;
if (cpp_video_capture) {
static int once = 1; static int once = 1;
if (once) { if (once) {
once = 0; once = 0;
do { do {
src = get_capture_frame(cap); src = get_capture_frame_cv(cap);
if (!src) return make_empty_image(0, 0, 0); if (!src) return make_empty_image(0, 0, 0);
} while (src->width < 1 || src->height < 1 || src->nChannels < 1); } while (src->width < 1 || src->height < 1 || src->nChannels < 1);
printf("Video stream: %d x %d \n", src->width, src->height); printf("Video stream: %d x %d \n", src->width, src->height);
} }
else else
src = get_capture_frame(cap); src = get_capture_frame_cv(cap);
}
else src = cvQueryFrame(cap);
if (cpp_video_capture)
if (!wait_for_stream(cap, src, dont_close)) return make_empty_image(0, 0, 0); if (!wait_for_stream(cap, src, dont_close)) return make_empty_image(0, 0, 0);
*in_img = (mat_cv *)cvCreateImage(cvSize(src->width, src->height), IPL_DEPTH_8U, c); *in_img = (mat_cv *)cvCreateImage(cvSize(src->width, src->height), IPL_DEPTH_8U, c);
cvResize(src, *in_img, CV_INTER_LINEAR); cvResize(src, *in_img, CV_INTER_LINEAR);
image tmp = ipl_to_image(src); image tmp = ipl_to_image(src);
image im = letterbox_image(tmp, w, h); image im = letterbox_image(tmp, w, h);
free_image(tmp); free_image(tmp);
if (cpp_video_capture) cvReleaseImage(&src); cvReleaseImage(&src);
if (c>1) rgbgr_image(im); if (c>1) rgbgr_image(im);
return im; return im;
} }
// ---------------------------------------- // ----------------------------------------
int get_stream_fps(cap_cv *cap_src, int cpp_video_capture)
{
CvCapture *cap = (CvCapture *)cap_src;
int fps = 25;
if (cpp_video_capture) {
fps = get_stream_fps_cpp(cap);
}
else {
fps = cvGetCaptureProperty(cap, CV_CAP_PROP_FPS);
}
return fps;
}
// ----------------------------------------
// ==================================================================== // ====================================================================
// Image Saving // Image Saving
// ==================================================================== // ====================================================================
@ -837,76 +831,6 @@ void draw_detections_cv_v3(mat_cv* show_img, detection *dets, int num, float thr
} }
// ---------------------------------------- // ----------------------------------------
void draw_detections_cv(mat_cv* show_img, int num, float thresh, box *boxes, float **probs, char **names, image **alphabet, int classes)
{
int i;
for (i = 0; i < num; ++i) {
int class_id = max_index(probs[i], classes);
float prob = probs[i][class_id];
if (prob > thresh) {
int width = show_img->height * .012;
if (0) {
width = pow(prob, 1. / 2.) * 10 + 1;
alphabet = 0;
}
printf("%s: %.0f%%\n", names[class_id], prob * 100);
int offset = class_id * 123457 % classes;
float red = get_color(2, offset, classes);
float green = get_color(1, offset, classes);
float blue = get_color(0, offset, classes);
float rgb[3];
//width = prob*20+2;
rgb[0] = red;
rgb[1] = green;
rgb[2] = blue;
box b = boxes[i];
int left = (b.x - b.w / 2.)*show_img->width;
int right = (b.x + b.w / 2.)*show_img->width;
int top = (b.y - b.h / 2.)*show_img->height;
int bot = (b.y + b.h / 2.)*show_img->height;
if (left < 0) left = 0;
if (right > show_img->width - 1) right = show_img->width - 1;
if (top < 0) top = 0;
if (bot > show_img->height - 1) bot = show_img->height - 1;
float const font_size = show_img->height / 1000.F;
CvPoint pt1, pt2, pt_text, pt_text_bg1, pt_text_bg2;
pt1.x = left;
pt1.y = top;
pt2.x = right;
pt2.y = bot;
pt_text.x = left;
pt_text.y = top - 12;
pt_text_bg1.x = left;
pt_text_bg1.y = top - (10 + 25 * font_size);
pt_text_bg2.x = right;
pt_text_bg2.y = top;
CvScalar color;
color.val[0] = red * 256;
color.val[1] = green * 256;
color.val[2] = blue * 256;
cvRectangle(show_img, pt1, pt2, color, width, 8, 0);
//printf("left=%d, right=%d, top=%d, bottom=%d, obj_id=%d, obj=%s \n", left, right, top, bot, class_id, names[class_id]);
cvRectangle(show_img, pt_text_bg1, pt_text_bg2, color, width, 8, 0);
cvRectangle(show_img, pt_text_bg1, pt_text_bg2, color, CV_FILLED, 8, 0); // filled
CvScalar black_color;
black_color.val[0] = 0;
CvFont font;
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, font_size, font_size, 0, font_size * 3, 8);
cvPutText(show_img, names[class_id], pt_text, &font, black_color);
}
}
}
// ==================================================================== // ====================================================================
// Draw Loss & Accuracy chart // Draw Loss & Accuracy chart
// ==================================================================== // ====================================================================
@ -1162,4 +1086,9 @@ void show_acnhors(int number_of_boxes, int num_of_clusters, float *rel_width_hei
} // extern "C" } // extern "C"
#else // OPENCV
int wait_key_cv(int delay) { return 0; }
int wait_until_press_key_cv() { return 0; }
void destroy_all_windows_cv() {}
#endif // OPENCV #endif // OPENCV

@ -40,7 +40,7 @@ void show_image_cv_ipl(mat_cv *disp, const char *name);
// Video Writer // Video Writer
write_cv *create_video_writer(char *out_filename, char c1, char c2, char c3, char c4, int fps, int width, int height, int is_color); write_cv *create_video_writer(char *out_filename, char c1, char c2, char c3, char c4, int fps, int width, int height, int is_color);
int write_frame_cv(write_cv *output_video_writer, mat_cv *show_img); void write_frame_cv(write_cv *output_video_writer, mat_cv *show_img);
void release_video_writer(write_cv **output_video_writer); void release_video_writer(write_cv **output_video_writer);
@ -62,11 +62,9 @@ int set_capture_property_cv(cap_cv *cap, int property_id, double value);
int set_capture_position_frame_cv(cap_cv *cap, int index); int set_capture_position_frame_cv(cap_cv *cap, int index);
// ... Video Capture // ... Video Capture
image get_image_from_stream(cap_cv *cap);
image get_image_from_stream_cpp(cap_cv *cap); image get_image_from_stream_cpp(cap_cv *cap);
image get_image_from_stream_resize(cap_cv *cap, int w, int h, int c, mat_cv** in_img, int cpp_video_capture, int dont_close); image get_image_from_stream_resize(cap_cv *cap, int w, int h, int c, mat_cv** in_img, int dont_close);
image get_image_from_stream_letterbox(cap_cv *cap, int w, int h, int c, mat_cv** in_img, int cpp_video_capture, int dont_close); image get_image_from_stream_letterbox(cap_cv *cap, int w, int h, int c, mat_cv** in_img, int dont_close);
int get_stream_fps(cap_cv *cap, int cpp_video_capture);
// Image Saving // Image Saving
@ -75,7 +73,6 @@ void save_cv_jpg(mat_cv *img, const char *name);
// Draw Detection // Draw Detection
void draw_detections_cv_v3(mat_cv* show_img, detection *dets, int num, float thresh, char **names, image **alphabet, int classes, int ext_output); void draw_detections_cv_v3(mat_cv* show_img, detection *dets, int num, float thresh, char **names, image **alphabet, int classes, int ext_output);
void draw_detections_cv(mat_cv* show_img, int num, float thresh, box *boxes, float **probs, char **names, image **alphabet, int classes);
// Draw Loss & Accuracy chart // Draw Loss & Accuracy chart
mat_cv* draw_train_chart(float max_img_loss, int max_batches, int number_of_lines, int img_size, int dont_show); mat_cv* draw_train_chart(float max_img_loss, int max_batches, int number_of_lines, int img_size, int dont_show);
@ -90,11 +87,11 @@ image image_data_augmentation(mat_cv* ipl, int w, int h,
// Show Anchors // Show Anchors
void show_acnhors(int number_of_boxes, int num_of_clusters, float *rel_width_height_array, model anchors_data, int width, int height); void show_acnhors(int number_of_boxes, int num_of_clusters, float *rel_width_height_array, model anchors_data, int width, int height);
#else #else // OPENCV
static int wait_key_cv(int delay) { return 0; } int wait_key_cv(int delay);
static int wait_until_press_key_cv() { return 0; } int wait_until_press_key_cv();
static void destroy_all_windows_cv() {} void destroy_all_windows_cv();
#endif // OPENCV #endif // OPENCV

@ -163,7 +163,7 @@ void generate_vid_rnn(char *cfgfile, char *weightfile)
next = NULL; next = NULL;
image last; image last;
for(i = 0; i < 25; ++i){ for(i = 0; i < 25; ++i){
image im = get_image_from_stream(cap); image im = get_image_from_stream_cpp(cap);
image re = resize_image(im, extractor.w, extractor.h); image re = resize_image(im, extractor.w, extractor.h);
feat = network_predict(extractor, re.data); feat = network_predict(extractor, re.data);
if(i > 0){ if(i > 0){

@ -13,8 +13,8 @@ void extract_voxel(char *lfile, char *rfile, char *prefix)
cap_cv *lcap = get_capture_video_stream(lfile); cap_cv *lcap = get_capture_video_stream(lfile);
cap_cv *rcap = get_capture_video_stream(rfile); cap_cv *rcap = get_capture_video_stream(rfile);
while(1){ while(1){
image l = get_image_from_stream(lcap); image l = get_image_from_stream_cpp(lcap);
image r = get_image_from_stream(rcap); image r = get_image_from_stream_cpp(rcap);
if(!l.w || !r.w) break; if(!l.w || !r.w) break;
if(count%100 == 0) { if(count%100 == 0) {
shift = best_3d_shift_r(l, r, -l.h/100, l.h/100); shift = best_3d_shift_r(l, r, -l.h/100, l.h/100);

Loading…
Cancel
Save