-
Notifications
You must be signed in to change notification settings - Fork 0
/
tlen.c
70 lines (58 loc) · 1.67 KB
/
tlen.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* tlen.c - Library for tlenization
* Using OpenCV
*
* Copyright (c) 2015 Denisov Sergey
*
* This file is released under the GPLv3
*
*/
#include <opencv/highgui.h>
#include <stdio.h>
#include "tlen.h"
static IplImage* img_resize(IplImage* src_img, int new_width, int new_height)
{
IplImage* des_img;
des_img = cvCreateImage(cvSize(new_width, new_height), src_img->depth, src_img->nChannels);
cvResize(src_img, des_img, CV_INTER_LINEAR);
return des_img;
}
void tlen_image(const char *in_file, const char *templ_file, const char *result_file, double level)
{
int x = 0;
int y = 0;
IplImage* dst;
IplImage* image, *gray_image;
IplImage* templ;
IplImage* new_templ;
int width, height;
double alpha, beta;
/* Get image */
image = cvLoadImage(in_file, 1);
assert(image != 0);
templ = cvLoadImage(templ_file, 1);
assert(templ != 0);
/* Size of template */
new_templ = img_resize(templ, image->width, image->height);
width = new_templ->width;
height = new_templ->height;
dst = cvCloneImage(new_templ);
alpha = level;
beta = 0.5;
/* Set area */
cvSetImageROI(image, cvRect(x, y, width, height));
/* Summ */
cvAddWeighted(image, alpha, new_templ, beta, 0.0, dst);
/* Free area */
cvResetImageROI(image);
/* Set black-white image */
gray_image = cvCreateImage(cvSize(image->width,image->height), 8, 1);
cvCvtColor(dst, gray_image, CV_RGB2GRAY);
cvSaveImage(result_file, gray_image, NULL);
/* Fre memory */
cvReleaseImage(&image);
cvReleaseImage(&gray_image);
cvReleaseImage(&templ);
cvReleaseImage(&new_templ);
cvReleaseImage(&dst);
}