-
Notifications
You must be signed in to change notification settings - Fork 0
/
ladybug_16bitTest.cpp
124 lines (99 loc) · 3.57 KB
/
ladybug_16bitTest.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
//=============================================================================
// Copyright © 2017 FLIR Integrated Imaging Solutions, Inc. All Rights Reserved.
//
// This software is the confidential and proprietary information of FLIR
// Integrated Imaging Solutions, Inc. ("Confidential Information"). You
// shall not disclose such Confidential Information and shall use it only in
// accordance with the terms of the license agreement you entered into
// with FLIR Integrated Imaging Solutions, Inc. (FLIR).
//
// FLIR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
// SOFTWARE, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE, OR NON-INFRINGEMENT. FLIR SHALL NOT BE LIABLE FOR ANY DAMAGES
// SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
// THIS SOFTWARE OR ITS DERIVATIVES.
//=============================================================================
//
//=============================================================================
// This example illustrates the simplest procedure of acquiring an image from a
// Ladybug camera.
//
// This program does:
// - create a context
// - initialize a camera
// - start transmission of images
// - grab an image
// - color process the grabbed image
// - save the 6 raw images in BMP files
// - destroy the context
//
//=============================================================================
#include <stdio.h>
#include <stdlib.h>
#include "ladybug.h"
#include "ladybugstream.h"
#include "ladybuggeom.h"
#include "opencv2/opencv.hpp"
#define _HANDLE_ERROR \
if( error != LADYBUG_OK ) \
{ \
printf( \
"Error: Ladybug library reported - %s\n", \
::ladybugErrorToString( error ) ); \
exit( 1 ); \
} \
\
int main( int /* argc */, char* /* argv[] */ )
{
// Initialize context.
LadybugContext context;
LadybugError error = ::ladybugCreateContext(&context);
_HANDLE_ERROR;
// Initialize the first ladybug on the bus.
printf( "Initializing...\n" );
error = ::ladybugInitializeFromIndex(context, 0);
_HANDLE_ERROR;
// Get camera info
LadybugCameraInfo caminfo;
error = ladybugGetCameraInfo(context, &caminfo);
_HANDLE_ERROR;
// Start up the camera according to device type and data format
printf("Starting %s (%u)...\n", caminfo.pszModelName, caminfo.serialHead);
error = ::ladybugStart(
context,
LADYBUG_DATAFORMAT_RAW16);
_HANDLE_ERROR;
// Grab a single image.
printf( "Grabbing image\n" );
error = LADYBUG_FAILED;
LadybugImage currentImage;
for ( int i = 0; i < 10 && error != LADYBUG_OK; i++)
{
printf(".");
error = ::ladybugGrabImage(context, ¤tImage);
}
printf("\n");
_HANDLE_ERROR;
printf("Saving images...\n");
for (unsigned int uiCamera = 0; uiCamera < LADYBUG_NUM_CAMERAS; uiCamera++)
{
std::ostringstream out;
out << "image" << uiCamera << ".png";
cv::Size size(currentImage.uiFullCols, currentImage.uiFullRows);
cv::Mat rawImage(size, CV_16UC1, currentImage.pData + (uiCamera * size.width*size.height*2));
cv::Mat image(size, CV_16UC3);
cv::Mat image2;
cv::cvtColor(rawImage, image, cv::COLOR_BayerBG2RGB);
//cv::resize(image, image2 ,cv::Size(0,0), 0.3,0.3);
//cv::imshow("aaa", image2);
//cv::waitKey(0);
cv::imwrite(out.str(), image);
}
// Destroy the context
printf( "Destroying context...\n" );
error = ::ladybugDestroyContext(&context);
_HANDLE_ERROR;
printf( "Done.\n" );
return 0;
}