-
Notifications
You must be signed in to change notification settings - Fork 14
/
Drogonfly_ImgRead.cpp
116 lines (101 loc) · 2.17 KB
/
Drogonfly_ImgRead.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
#include "Drogonfly_ImgRead.h"
Drogonfly_ImgRead::Drogonfly_ImgRead(void)
: numCameras(0)
, cvImg(NULL)
{
}
Drogonfly_ImgRead::~Drogonfly_ImgRead(void)
{
cvReleaseImage(&cvImg);
ClearBuffer();
}
// Initial the Dragonfly Camera
int Drogonfly_ImgRead::Camera_Intial(void)
{
Image convertedImage;
//detect the num of cameras
error=busMgr.GetNumOfCameras(&numCameras);
if (error != PGRERROR_OK)
{
//PrintError( error );
error.PrintErrorTrace();
return -1;
}
cout<<"Number of cameras detected: " << numCameras << endl;
//get the index of camera
error=busMgr.GetCameraFromIndex(0,&guid);
if (error!=PGRERROR_OK)
{
error.PrintErrorTrace();
return -1;
}
// Connect to a camera
error = cam.Connect(&guid);
if (error != PGRERROR_OK)
{
error.PrintErrorTrace();
return -1;
}
// Start capturing images
error = cam.StartCapture();
if (error != PGRERROR_OK)
{
error.PrintErrorTrace();
return -1;
}
// Retrieve an image
error = cam.RetrieveBuffer( &rawImage );
if (error != PGRERROR_OK)
{
error.PrintErrorTrace();
return -1;
}
//convert the raw image to the format of BGR
error=rawImage.Convert(PIXEL_FORMAT_BGR,&convertedImage);
if (error != PGRERROR_OK)
{
error.PrintErrorTrace();
return -1;
}
//copy the data to IplImage
cvImg=cvCreateImage(cvSize(rawImage.GetCols(), rawImage.GetRows()), 8, 3);
cout<<"Dragonfly Initial Done!"<<endl;
}
// transfer the image data from camera to IplImage
IplImage* Drogonfly_ImgRead::Camera2IplImage(void)
{
Image convertedImage;
error= cam.RetrieveBuffer(&rawImage);
/*if (error!=PGRERROR_OK)
{
error.PrintErrorTrace();
return NULL;
}*/
error = rawImage.Convert( FlyCapture2::PIXEL_FORMAT_BGR, &convertedImage);
if (error !=PGRERROR_OK)
{
error.PrintErrorTrace();
return NULL;
}
memcpy(cvImg->imageData, convertedImage.GetData(), convertedImage.GetDataSize());
if( !cvImg )
{
cout<<"No data in IplImage!"<<endl;
return NULL;
}
return cvImg;
}
// clear the image data in the camera
void Drogonfly_ImgRead::ClearBuffer(void)
{
error=cam.StopCapture();
if (error != PGRERROR_OK)
{
error.PrintErrorTrace();
}
error=cam.Disconnect();
if (error!= PGRERROR_OK)
{
error.PrintErrorTrace();
}
}