This repository has been archived by the owner on Mar 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FLIRCamera.cpp
121 lines (114 loc) · 4.89 KB
/
FLIRCamera.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
/* Copyright (C) 2019 Brett Dong
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "FLIRCamera.h"
#include <iostream>
FLIRCamera::FLIRCamera()
{
m_system = Spinnaker::System::GetInstance();
m_initialized = false;
}
FLIRCamera::~FLIRCamera()
{
if(m_initialized)
{
m_camera->DeInit();
m_camera = nullptr;
m_initialized = false;
}
m_system->ReleaseInstance();
std::cout << "FLIR camera deinitialized" << std::endl;
}
bool FLIRCamera::Initialize()
{
std::cout << "FLIR camera initialization" << std::endl;
const Spinnaker::LibraryVersion spinnaker_version = m_system->GetLibraryVersion();
std::cout << "Spinnaker SDK version: " << spinnaker_version.major << "." << spinnaker_version.minor << "." << spinnaker_version.type << "." << spinnaker_version.build << std::endl;
Spinnaker::CameraList camera_list = m_system->GetCameras();
if(camera_list.GetSize() == 0)
{
std::cout << "FLIR camera not found" << std::endl;
camera_list.Clear();
return false;
}
std::cout << "Discovered " << camera_list.GetSize() << " FLIR cameras, using #0" << std::endl;
m_camera = camera_list.GetByIndex(0);
camera_list.Clear();
m_TL_device = &(m_camera->GetTLDeviceNodeMap());
m_camera->Init();
m_node_map = &(m_camera->GetNodeMap());
m_initialized = true;
std::cout << "Camera #0 initialized" << std::endl;
std::cout << "Resolution: " << m_camera->Width.GetValue() << "x" << m_camera->Height.GetValue() << std::endl;
std::cout << "Exposure time: " << m_camera->ExposureTime.GetValue() / 1000.0 << " ms" << std::endl;
std::cout << "Pixel format: " << m_camera->PixelFormat.GetCurrentEntry()->GetSymbolic() << std::endl;
return true;
}
bool FLIRCamera::BeginAcquisition()
{
if(!m_initialized)
{
std::cout << "Attempt to begin acquisition before initialization" << std::endl;
return false;
}
Spinnaker::GenApi::CEnumerationPtr p_acquisition_mode = m_node_map->GetNode("AcquisitionMode");
if(!Spinnaker::GenApi::IsAvailable(p_acquisition_mode) || !Spinnaker::GenApi::IsWritable(p_acquisition_mode))
{
std::cout << "Acquisition mode unavailable or not writable" << std::endl;
return false;
}
Spinnaker::GenApi::CEnumEntryPtr p_acquisition_mode_continuous = p_acquisition_mode->GetEntryByName("Continuous");
if(!Spinnaker::GenApi::IsAvailable(p_acquisition_mode_continuous) || !Spinnaker::GenApi::IsReadable(p_acquisition_mode_continuous))
{
std::cout << "Continuous acqusition mode entry unavailable or not readable" << std::endl;
return false;
}
const uint64_t acquisition_mode_continuous = p_acquisition_mode_continuous->GetValue();
p_acquisition_mode->SetIntValue(acquisition_mode_continuous);
std::cout << "Acquisition mode set to continuous" << std::endl;
m_camera->BeginAcquisition();
std::cout << "Acquisition begin" << std::endl;
return true;
}
bool FLIRCamera::EndAcquisition()
{
if(!m_initialized)
{
std::cout << "Attempt to end acquisition before initialization" << std::endl;
return false;
}
m_camera->EndAcquisition();
return true;
}
bool FLIRCamera::RetrieveImage(cv::Mat &image)
{
Spinnaker::ImagePtr p_result_image = m_camera->GetNextImage();
if(p_result_image->IsIncomplete())
{
std::cout << "Image incomplete: " << Spinnaker::Image::GetImageStatusDescription(p_result_image->GetImageStatus()) << std::endl;
return false;
}
const size_t width = p_result_image->GetWidth();
const size_t height = p_result_image->GetHeight();
Spinnaker::ImagePtr p_converted_image = p_result_image->Convert(Spinnaker::PixelFormatEnums::PixelFormat_BGR8, Spinnaker::ColorProcessingAlgorithm::HQ_LINEAR);
image = cv::Mat(height, width, CV_8UC3, p_converted_image->GetData(), p_converted_image->GetStride());
p_result_image->Release();
return true;
}