-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutputimg.cpp
151 lines (132 loc) · 4.7 KB
/
outputimg.cpp
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <stdio.h>
#include "def_general.h"
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "procimg.h"
#include "outputimg.h"
int OutPutImage(IplImage *img)
// 画像をファイルに保存する.ファイル名は自動的に連番になる
{
static int n = 0;
char filename[1024];
sprintf(filename, "output%03d.jpg", n++);
cvSaveImage( filename, img );
return 0;
}
int SetPixU( IplImage *img, int x, int y, unsigned char *val )
// imgの(x,y)にvalをセットする(unsigned)
{
int i, ws, bpp;
if ( x < 0 || x >= img->width || y < 0 || y >= img->height ) return 0; // 画像の範囲を超える
ws = img->widthStep;
bpp = (int)((img->depth & 0x0ff) / 8) * img->nChannels; // ピクセルあたりのバイト数
for ( i = 0; i < bpp; i++ )
img->imageData[ws*y + x*bpp + i] = val[i];
return 1;
}
int GetPixU( IplImage *img, int x, int y, unsigned char *val )
// imgの(x,y)をvalにセットする(unsigned)
{
int i, ws, bpp;
if ( x < 0 || x >= img->width || y < 0 || y >= img->height ) return 0; // 画像の範囲を超える
ws = img->widthStep;
bpp = (int)((img->depth & 0x0ff) / 8) * img->nChannels; // ピクセルあたりのバイト数
for ( i = 0; i < bpp; i++ )
val[i] = img->imageData[ws*y + x*bpp + i];
return 1;
}
IplImage *MakeFeaturePointImage( IplImage *orig, IplImage *connected, CvPoint *ps, int num )
// 特徴点画像の作成(入力画像はグレイスケール)
{
int i, j, p, con_flag = 0;
IplImage *fp_img, *fp;
unsigned char val[4];
cvNot( connected, connected );
fp_img = cvCreateImage( cvGetSize( orig ), IPL_DEPTH_8U, 3 );
fp = cvCreateImage( cvGetSize( orig ), IPL_DEPTH_8U, 3 );
cvZero( fp_img );
cvNot( fp_img, fp_img );
if ( fp_img == NULL ) return NULL;
for ( j = 0; j < orig->height; j++ ) {
for ( i = 0; i < orig->width; i++ ) {
con_flag = 0;
GetPixU( connected, i, j, val );
if ( val[0] != 255 ) {
val[0] = 0;
val[1] = 255;
val[2] = 0;
SetPixU( fp_img, i, j, val );
con_flag = 1;
}
GetPixU( orig, i, j, val );
if ( val[0] != 255 ) {
if ( con_flag ) {
val[1] = val[0];
val[0] = 0;
val[2] = 0;
SetPixU( fp_img, i, j, val );
}
else {
val[1] = val[0];
val[2] = val[0];
SetPixU( fp_img, i, j, val );
}
}
}
}
for ( p = 0; p < num; p++ ) {
cvCircle( fp_img, ps[p], 4, cRed, CV_FILLED, CV_AA, 0 );
// cvCircle( fp_img, ps[p], 4, cWhite, CV_FILLED, CV_AA, 0 );
//cvCircle( fp, ps[p], 5, cWhite, CV_FILLED, CV_AA, 0 );
}
cvNot( fp, fp );
//OutPutImage(fp);
return fp_img;
}
#define kDrawCorHMargin (100)
#define kDrawCorVMargin (100)
#define kDrawCorSpace (400)
#define kDrawCorScale (0.5)
#define kDrawCorRectThick (4)
#define kDrawCorPtRad (4)
#define kDrawCorLineThick (4)
void DrawCor( CvPoint *ps, int num, CvSize img_size, int res, CvPoint *corps, int cornum, CvSize corsize, int pcor[][2], int pcornum )
{
int i, width_all, height_all;
IplImage *img;
img_size.height = 4368;
img_size.width = 2912;
corsize.height = 2200;
corsize.width = 1700;
width_all = kDrawCorHMargin * 2 + kDrawCorSpace + img_size.width + (int)(corsize.width * kDrawCorScale);
height_all = kDrawCorVMargin * 2 + std::max( img_size.height, (int)(corsize.height * kDrawCorScale) );
// printf( "%d,%d\n", width_all, height_all );
img = cvCreateImage( cvSize( width_all, height_all ), IPL_DEPTH_8U, 3 );
cvSet( img, cWhite, NULL ); // 白で塗りつぶす
// 検索質問の枠を描画
cvRectangle( img, cvPoint( kDrawCorHMargin, kDrawCorVMargin ), \
cvPoint( kDrawCorHMargin + img_size.width, kDrawCorVMargin + img_size.height ), \
cBlack, kDrawCorRectThick, CV_AA, 0 );
// 検索質問の特徴点の描画
for ( i = 0; i < num; i++ ) {
cvCircle( img, cvPoint( kDrawCorHMargin + ps[i].x, kDrawCorVMargin + ps[i].y ), kDrawCorPtRad, cBlack, -1, CV_AA, 0 );
}
// 登録画像の枠を描画
cvRectangle( img, cvPoint( kDrawCorHMargin + img_size.width + kDrawCorSpace, kDrawCorVMargin), \
cvPoint( kDrawCorHMargin + img_size.width + kDrawCorSpace + (int)(corsize.width * kDrawCorScale), kDrawCorVMargin + (int)(corsize.height * kDrawCorScale) ), \
cBlack, kDrawCorRectThick, CV_AA, 0 );
// 登録画像の特徴点の描画
for ( i = 0; i < cornum; i++ ) {
cvCircle( img, cvPoint( kDrawCorHMargin + img_size.width + kDrawCorSpace + (int)(corps[i].x * kDrawCorScale), kDrawCorVMargin + (int)(corps[i].y * kDrawCorScale) ), \
kDrawCorPtRad, cBlack, -1, CV_AA, 0 );
}
// 対応関係の描画
//for ( i = 0; i < pcornum; i++ ) {
// cvLine( img, cvPoint( kDrawCorHMargin + ps[pcor[i][0]].x, kDrawCorVMargin + ps[pcor[i][0]].y ),
// cvPoint( kDrawCorHMargin + img_size.width + kDrawCorSpace + (int)(corps[pcor[i][1]].x * kDrawCorScale), kDrawCorVMargin + (int)(corps[pcor[i][1]].y * kDrawCorScale) ),
// cRed, kDrawCorLineThick, CV_AA, 0 );
//}
OutPutImage( img );
cvReleaseImage( &img );
}