-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathN900Helpers.cpp
executable file
·152 lines (140 loc) · 4.27 KB
/
N900Helpers.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
152
#include <N900Helpers.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
IplImage *
capture_yuv24 ( const FCam::Frame & frame )
{
const FCam::Image & image = frame.image ();
IplImage * img = cvCreateImage ( cvSize ( image.width (), image.height () ),
IPL_DEPTH_8U, 3 );
for ( unsigned int i = 0; i < image.height (); ++i )
{
for ( unsigned int j = 0; j < image.width (); j += 2 )
{
unsigned char * pixels = image ( j, i );
CV_IMAGE_ELEM ( img, uchar, i, j * 3 ) = pixels[1];
CV_IMAGE_ELEM ( img, uchar, i, j * 3 + 1 ) = pixels[2];
CV_IMAGE_ELEM ( img, uchar, i, j * 3 + 2 ) = pixels[0];
CV_IMAGE_ELEM ( img, uchar, i, j * 3 + 3 ) = pixels[3];
CV_IMAGE_ELEM ( img, uchar, i, j * 3 + 4 ) = pixels[2];
CV_IMAGE_ELEM ( img, uchar, i, j * 3 + 5 ) = pixels[0];
}
}
return img;
}
void render_yuv24 ( IplImage * )
{
/* if (img->width != 640 || img->height != 480)
* {
* return;
* }
* for (int i = 0; i < img->height; ++i)
* {
* for (int j = 0; j < img->width; j += 2)
* {
* unsigned char * pixels = &CV_IMAGE_ELEM (img, uchar, i, j*3);
* char * dest = (char *)Framebuffer::GetInstance().GetBuffer();
* dest[i*img->width*2 + j*2] = pixels[1];
* dest[i*img->width*2 + j*2 + 1] = pixels[0];
* dest[i*img->width*2 + j*2 + 2] = pixels[2];
* dest[i*img->width*2 + j*2 + 3] = pixels[3];
* }
* }
*/}
void save_yuv24 ( IplImage * img, const std::string & fname )
{
cvCvtColor ( img, img, CV_YCrCb2RGB );
cvSaveImage ( fname.c_str (), img );
}
IplImage *
capture_gray ( const FCam::Frame & frame )
{
const FCam::Image & image = frame.image ();
IplImage * img = cvCreateImage ( cvSize ( image.width (), image.height () ),
IPL_DEPTH_8U, 1 );
for ( unsigned int i = 0; i < image.height (); ++i )
{
for ( unsigned int j = 0; j < image.width (); j += 2 )
{
unsigned char * pixels = image ( j, i );
CV_IMAGE_ELEM ( img, uchar, i, j ) = pixels[1];
CV_IMAGE_ELEM ( img, uchar, i, j + 1 ) = pixels[3];
}
}
return img;
}
void render_gray ( IplImage * )
{
/* if (img->width != 640 || img->height != 480)
* {
* return;
* }
* for (int i = 0; i < img->height; ++i)
* {
* for (int j = 0; j < img->width; ++j)
* {
* unsigned char * pixels = &CV_IMAGE_ELEM (img, uchar, i, j);
* char * dest = (char *)Framebuffer::GetInstance().GetBuffer();
* dest[i*img->width*2 + j*2] = 128;
* dest[i*img->width*2 + j*2 + 1] = pixels[0];
* }
* }
*/}
void save_gray ( IplImage * img, const std::string & fname )
{
cvSaveImage ( fname.c_str (), img );
}
IplImage *
capture_rgb24 ( const FCam::Frame & frame )
{
/*FCam::Image image = demosaic (frame);
* IplImage * img = cvCreateImage (cvSize(image.width(), image.height()),
* IPL_DEPTH_8U, 3);
* for (unsigned int i = 0; i < image.height(); ++i)
* {
* for (unsigned int j = 0; j < image.width(); ++j)
* {
* unsigned char * pixels = image(j, i);
* CV_IMAGE_ELEM (img, uchar, i, j*3) = pixels[0];
* CV_IMAGE_ELEM (img, uchar, i, j*3 + 1) = pixels[1];
* CV_IMAGE_ELEM (img, uchar, i, j*3 + 2) = pixels[2];
* }
* }
* return img;*/
IplImage * img = capture_yuv24 ( frame );
cvCvtColor ( img, img, CV_YCrCb2RGB );
return img;
}
void render_rgb24 ( IplImage * img )
{
cvCvtColor ( img, img, CV_RGB2YCrCb );
render_yuv24 ( img );
return;
/*if (img->width != 640 || img->height != 480)
* {
* return;
* }
* IplImage * foo = cvCreateImage (cvSize(640,480), IPL_DEPTH_8U, 1);
* printf ("%d %d\n", img->width, img->height);
* cvSplit (img, foo, 0, 0, 0);
* render_gray (foo);
* cvReleaseImage (&foo);
* return;
* for (int i = 0; i < img->height; ++i)
* {
* for (int j = 0; j < img->width; ++j)
* {
* unsigned char * pixels = &CV_IMAGE_ELEM (img, uchar, i, j*3);
* char * dest = (char *)Framebuffer::GetInstance().GetBuffer();
* dest[i*img->width*4 + j*4] = pixels[0];
* dest[i*img->width*4 + j*4 + 1] = pixels[1];
* dest[i*img->width*4 + j*4 + 2] = pixels[2];
* dest[i*img->width*4 + j*4 + 3] = 0;
* }
* }*/
}
void save_rgb24 ( IplImage * img, const std::string & fname )
{
//cvCvtColor (img, img, CV_RGB2BGR);
cvSaveImage ( fname.c_str (), img );
}