From 351996d9f0390ef44412fa678bc7a073a94e23e5 Mon Sep 17 00:00:00 2001
From: AlexeyAB <alexeyab84@gmail.com>
Date: Thu, 16 Mar 2017 18:49:36 +0000
Subject: [PATCH] Fixed memory leak in DLL, added load_image() & free_image(), added read_names_from_file()
---
src/image.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 47 insertions(+), 4 deletions(-)
diff --git a/src/image.c b/src/image.c
index e744782..d090cc7 100644
--- a/src/image.c
+++ b/src/image.c
@@ -437,6 +437,28 @@
cvReleaseImage(&buffer);
}
cvShowImage(buff, disp);
+
+ {
+ CvSize size;
+ {
+ size.width = disp->width, size.height = disp->height;
+ }
+
+ static CvVideoWriter* output_video = NULL; // cv::VideoWriter output_video;
+ if (output_video == NULL)
+ {
+ printf("\n SRC output_video = %p \n", output_video);
+ const char* output_name = "test_dnn_out.avi";
+ //output_video = cvCreateVideoWriter(output_name, CV_FOURCC('H', '2', '6', '4'), 25, size, 1);
+ output_video = cvCreateVideoWriter(output_name, CV_FOURCC('D', 'I', 'V', 'X'), 25, size, 1);
+ //output_video = cvCreateVideoWriter(output_name, CV_FOURCC('M', 'J', 'P', 'G'), 25, size, 1);
+ printf("\n cvCreateVideoWriter, DST output_video = %p \n", output_video);
+ }
+
+ cvWriteFrame(output_video, disp);
+ printf("\n cvWriteFrame \n");
+ }
+
cvReleaseImage(&disp);
}
#endif
@@ -532,11 +554,8 @@
}
#endif
-void save_image(image im, const char *name)
+void save_image_png(image im, const char *name)
{
-#ifdef OPENCV
- save_image_jpg(im, name);
-#else
char buff[256];
//sprintf(buff, "%s (%d)", name, windows);
sprintf(buff, "%s.png", name);
@@ -550,6 +569,14 @@
int success = stbi_write_png(buff, im.w, im.h, im.c, data, im.w*im.c);
free(data);
if(!success) fprintf(stderr, "Failed to write image %s\n", buff);
+}
+
+void save_image(image im, const char *name)
+{
+#ifdef OPENCV
+ save_image_jpg(im, name);
+#else
+ save_image_png(im, name);
#endif
}
@@ -748,6 +775,22 @@
#endif
}
+image resize_max(image im, int max)
+{
+ int w = im.w;
+ int h = im.h;
+ if(w > h){
+ h = (h * max) / w;
+ w = max;
+ } else {
+ w = (w * max) / h;
+ h = max;
+ }
+ if(w == im.w && h == im.h) return im;
+ image resized = resize_image(im, w, h);
+ return resized;
+}
+
image resize_min(image im, int min)
{
int w = im.w;
--
Gitblit v1.10.0