src
main.cpp
Go to the documentation of this file.
1
#include <
cv_bridge/cv_bridge.h
>
2
#include <sensor_msgs/Image.h>
3
#include <std_msgs/Float32.h>
4
5
#include <
mlx90640_thermal_camera/mlx90640.h
>
6
7
int
FPS
;
8
int
UPSCALE_FACTOR
;
9
10
float
*
rawThermalImage
;
11
cv::Mat
grayscaleImage
(
SENSOR_W
,
SENSOR_H
, CV_32FC1);
12
cv::Mat
normalizedImage
;
13
cv::Mat
coloredImage
;
14
cv::Mat
upscaledImage
;
15
sensor_msgs::ImagePtr
normalizedThermalImage
;
16
17
void
constructNormalizedThermalImage
(
float
minTemp,
float
maxTemp) {
18
for
(
int
y = 0; y < 24; y++) {
19
for
(
int
x = 0; x < 32; x++) {
20
int
index = y * 32 + x;
21
grayscaleImage
.at<
float
>(y, x) =
22
(
rawThermalImage
[index] - minTemp) / (maxTemp - minTemp) * 255.0
f
;
23
}
24
}
25
26
grayscaleImage
.convertTo(
normalizedImage
, CV_8UC1);
27
cv::cvtColor(
normalizedImage
,
coloredImage
, cv::COLOR_GRAY2BGR);
28
cv::resize(
coloredImage
,
upscaledImage
,
29
cv::Size(
SENSOR_H
*
UPSCALE_FACTOR
,
SENSOR_W
*
UPSCALE_FACTOR
));
30
31
normalizedThermalImage
=
32
cv_bridge::CvImage
(std_msgs::Header(),
"bgr8"
,
upscaledImage
)
33
.
toImageMsg
();
34
}
35
36
int
main
(
int
argc,
char
**argv) {
37
rawThermalImage
= (
float
*)malloc(
SENSOR_W
*
SENSOR_H
*
sizeof
(
float
));
38
ros::init
(argc, argv,
"mlx90640"
);
39
ros::NodeHandle
nh(
"~"
);
40
41
if
(!nh.
getParam
(
"fps"
,
FPS
)) {
42
ROS_ERROR
(
"Could not load param: fps"
);
43
return
1;
44
}
45
if
(!nh.
getParam
(
"upscale_factor"
,
UPSCALE_FACTOR
)) {
46
ROS_ERROR
(
"Could not load param: upscale_factor"
);
47
return
1;
48
}
49
50
ros::Publisher
minTempPub =
51
nh.
advertise
<std_msgs::Float32>(
"/mlx90640/temperature/min"
,
FPS
);
52
ros::Publisher
maxTempPub =
53
nh.
advertise
<std_msgs::Float32>(
"/mlx90640/temperature/max"
,
FPS
);
54
ros::Publisher
normalizedThermalImagePub =
55
nh.
advertise
<sensor_msgs::Image>(
"/mlx90640/image/normalized"
,
FPS
);
56
ros::Rate
loopRate(
FPS
);
57
58
MLX90640
thermalCamera(
FPS
);
59
std_msgs::Float32 minTemp, maxTemp;
60
61
while
(
ros::ok
()) {
62
ros::spinOnce
();
63
64
thermalCamera.
see
();
65
thermalCamera.
copyRawImage
(
rawThermalImage
);
66
minTemp.data = thermalCamera.
getMin
();
67
maxTemp.data = thermalCamera.
getMax
();
68
constructNormalizedThermalImage
(minTemp.data, maxTemp.data);
69
70
minTempPub.
publish
(minTemp);
71
maxTempPub.publish(maxTemp);
72
normalizedThermalImagePub.publish(
normalizedThermalImage
);
73
74
loopRate.sleep();
75
}
76
77
return
0;
78
}
normalizedImage
cv::Mat normalizedImage
Definition:
main.cpp:12
upscaledImage
cv::Mat upscaledImage
Definition:
main.cpp:14
ros::Publisher
cv_bridge::CvImage::toImageMsg
sensor_msgs::ImagePtr toImageMsg() const
rawThermalImage
float * rawThermalImage
Definition:
main.cpp:10
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros::NodeHandle::getParam
bool getParam(const std::string &key, bool &b) const
ros::spinOnce
ROSCPP_DECL void spinOnce()
main
int main(int argc, char **argv)
Definition:
main.cpp:36
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
coloredImage
cv::Mat coloredImage
Definition:
main.cpp:13
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
ros::ok
ROSCPP_DECL bool ok()
f
f
MLX90640::copyRawImage
void copyRawImage(float *pointer)
Definition:
mlx90640.cpp:59
MLX90640::getMax
float getMax()
Definition:
mlx90640.cpp:67
SENSOR_H
#define SENSOR_H
Definition:
mlx90640.h:12
MLX90640::getMin
float getMin()
Definition:
mlx90640.cpp:65
SENSOR_W
#define SENSOR_W
Definition:
mlx90640.h:11
mlx90640.h
constructNormalizedThermalImage
void constructNormalizedThermalImage(float minTemp, float maxTemp)
Definition:
main.cpp:17
UPSCALE_FACTOR
int UPSCALE_FACTOR
Definition:
main.cpp:8
FPS
int FPS
Definition:
main.cpp:7
cv_bridge.h
ROS_ERROR
#define ROS_ERROR(...)
MLX90640::see
void see()
Definition:
mlx90640.cpp:37
cv_bridge::CvImage
ros::Rate
MLX90640
Definition:
mlx90640.h:14
ros::NodeHandle
normalizedThermalImage
sensor_msgs::ImagePtr normalizedThermalImage
Definition:
main.cpp:15
grayscaleImage
cv::Mat grayscaleImage(SENSOR_W, SENSOR_H, CV_32FC1)
mlx90640_thermal_camera
Author(s):
autogenerated on Sat Sep 16 2023 02:13:29