33 #include <Base/Image/Image.hh>
34 #include <Base/Image/ImageIO.hh>
35 #include <1394Camera.h>
45 enum ColorFormat { RGB8, RGB16, MONO8, MONO16, YUV411, YUV422, YUV444 };
47 std::ostream&
operator<< (std::ostream &out,
const ColorFormat &color)
51 case RGB8:
return out <<
"RGB 8";
52 case RGB16:
return out <<
"RGB 16";
53 case MONO8:
return out <<
"MONO 8";
54 case MONO16:
return out <<
"MONO 16";
55 case YUV411:
return out <<
"YUV 4:1:1";
56 case YUV422:
return out <<
"YUV 4:2:2";
57 case YUV444:
return out <<
"YUV 4:4:4";
68 VideoSetting(
int f,
int m,
int w,
int h, ColorFormat c)
81 VideoSettings() : INVALID_SETTING(-1, -1, 0, 0, RGB8)
86 settings.push_back(VideoSetting(0, 0, 160, 120, YUV444));
87 settings.push_back(VideoSetting(0, 1, 320, 240, YUV422));
88 settings.push_back(VideoSetting(0, 2, 640, 480, YUV411));
89 settings.push_back(VideoSetting(0, 3, 640, 480, YUV422));
90 settings.push_back(VideoSetting(0, 4, 640, 480, RGB8));
91 settings.push_back(VideoSetting(0, 5, 640, 480, MONO8));
92 settings.push_back(VideoSetting(0, 6, 640, 480, MONO16));
94 settings.push_back(VideoSetting(1, 0, 800, 600, YUV422));
95 settings.push_back(VideoSetting(1, 1, 800, 600, RGB8));
96 settings.push_back(VideoSetting(1, 2, 800, 600, MONO8));
97 settings.push_back(VideoSetting(1, 6, 800, 600, MONO16));
98 settings.push_back(VideoSetting(1, 3, 1024, 768, YUV422));
99 settings.push_back(VideoSetting(1, 4, 1024, 768, RGB8));
100 settings.push_back(VideoSetting(1, 5, 1024, 768, MONO8));
101 settings.push_back(VideoSetting(1, 7, 1024, 768, MONO16));
103 settings.push_back(VideoSetting(2, 0, 1280, 960, YUV422));
104 settings.push_back(VideoSetting(2, 1, 1280, 960, RGB8));
105 settings.push_back(VideoSetting(2, 2, 1280, 960, MONO8));
106 settings.push_back(VideoSetting(2, 6, 1280, 960, MONO16));
107 settings.push_back(VideoSetting(2, 3, 1600, 1200, YUV422));
108 settings.push_back(VideoSetting(2, 4, 1600, 1200, RGB8));
109 settings.push_back(VideoSetting(2, 5, 1600, 1200, MONO8));
110 settings.push_back(VideoSetting(2, 7, 1600, 1200, MONO16));
113 VideoSetting findFormatAndMode(
int vformat,
int vmode)
const
115 std::vector<VideoSetting>::const_iterator it;
116 for (it = settings.begin(); it != settings.end(); it++)
117 if (it->vformat == vformat && it->vmode == vmode)
119 return INVALID_SETTING;
122 VideoSetting findSizeAndColor(
int width,
int height, ColorFormat color)
const
124 std::vector<VideoSetting>::const_iterator it;
125 for (it = settings.begin(); it != settings.end(); it++)
126 if (it->width == width && it->height == height && it->color == color)
128 return INVALID_SETTING;
132 std::vector<VideoSetting> settings;
133 const VideoSetting INVALID_SETTING;
136 int main(
int argc,
char *argv[])
138 cout <<
"Usage : ExampleCMU1394 [<cam id>] [<video format>] [<video mode>] [<fps mode>] [<image num>]"
142 float fps[8] = { 1.875f, 3.75f, 7.5f, 15.0f, 30.0f, 60.0f, 120.0f, 240.0f };
143 VideoSettings vsettings;
146 int cam_id = argc > 1 ? atoi(argv[1]) : 0;
147 int vformat_id = argc > 2 ? atoi(argv[2]) : 2;
148 int vmode_id = argc > 3 ? atoi(argv[3]) : 3;
149 int fps_id = argc > 4 ? atoi(argv[4]) : 2;
150 int image_number = argc > 5 ? atoi(argv[5]) : 1;
154 if (camera.RefreshCameraList() == 0) {
155 cout <<
"Warning : No cameras found!" << endl;
158 if (camera.SelectCamera(cam_id) != CAM_SUCCESS) {
159 cout <<
"Error : Failed to select camera " << cam_id <<
"!" << endl;
162 if (camera.InitCamera() != CAM_SUCCESS) {
163 cout <<
"Error : Failed to initialize camera " << cam_id <<
"!" << endl;
168 camera.SetVideoFormat(vformat_id);
169 camera.SetVideoMode(vmode_id);
170 camera.SetVideoFrameRate(fps_id);
173 unsigned long width = 0, height = 0;
174 camera.GetVideoFrameDimensions(&width, &height);
175 vformat_id = camera.GetVideoFormat();
176 vmode_id = camera.GetVideoMode();
177 fps_id = camera.GetVideoFrameRate();
178 VideoSetting vsetting = vsettings.findFormatAndMode(vformat_id, vmode_id);
179 const bool grey_image = (vsetting.color == MONO8 || vsetting.color == MONO16);
180 const ColorFormat color_format = vsetting.color;
181 if (vsetting.width != (
int)width || vsetting.height != (int)height) {
182 cout <<
"Warning : Video setting is not consistent with specification!" << endl;
186 const unsigned int channels = 3;
187 unsigned long bytes = width * height * channels;
191 if (camera.StartImageAcquisition() != CAM_SUCCESS) {
192 cout <<
"Error : Failed to start image capture!" << endl;
195 cout <<
"Started capture with image size " << width <<
" x " << height
196 <<
", color format " << color_format <<
" at " << fps[fps_id] <<
" fps" << endl
197 <<
"(video format " << vformat_id <<
", video mode " << vmode_id <<
")" << endl
198 <<
"Capturing " << image_number <<
" image" << (image_number != 1 ?
"s" :
"") << endl;
200 for (
int image_no = 0; image_no < image_number; image_no++)
203 if (camera.AcquireImage() != CAM_SUCCESS) {
204 cout <<
"Error : Failed to capture image!" << endl;
209 switch (color_format)
212 camera.getRGB(image.GetImageData(), bytes);
215 camera.RGB16toRGB(image.GetImageData(), bytes);
218 camera.YtoRGB(image.GetImageData(), bytes);
221 camera.Y16toRGB(image.GetImageData(), bytes);
224 camera.YUV411toRGB(image.GetImageData(), bytes);
227 camera.YUV422toRGB(image.GetImageData(), bytes);
230 camera.YUV444toRGB(image.GetImageData(), bytes);
236 sprintf(filename,
"image-%04d.%s", image_no, grey_image ?
"pgm" :
"ppm");
239 cout <<
"Wrote " << filename << endl << flush;
243 if (camera.IsAcquiring())
244 camera.StopImageAcquisition();
245 cout <<
"Closed camera connection" << endl;
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)