opencv_conversions.cpp
Go to the documentation of this file.
1 #include "opencv_conversions.h"
2 
3 #include <cstring>
4 
5 #include <opencv2/imgproc.hpp>
6 
7 #include <Image/ByteImage.h>
8 
10 
11 #include <VisionX/interface/components/Calibration.h>
12 
13 
14 void visionx::convertIvtRgbToCvGray(const CByteImage& ivt_rgb, cv::Mat& cv_gray)
15 {
16  cv::Mat cv_rgb(cv::Size(ivt_rgb.width, ivt_rgb.height), CV_8UC3);
17  std::memcpy(cv_rgb.data, ivt_rgb.pixels,
18  static_cast<unsigned int>(ivt_rgb.width * ivt_rgb.height * ivt_rgb.bytesPerPixel));
19 
20  cv_gray.create(cv::Size(ivt_rgb.width, ivt_rgb.height), CV_8UC1);
21  cv::cvtColor(cv_rgb, cv_gray, cv::COLOR_RGB2GRAY);
22 }
23 
24 
25 cv::Mat visionx::makeCameraMatrix(const visionx::CameraParameters& cameraParam)
26 {
27  ARMARX_CHECK_EQUAL(cameraParam.focalLength.size(), 2);
28  ARMARX_CHECK_EQUAL(cameraParam.principalPoint.size(), 2);
29  const float nodalPointX = cameraParam.principalPoint.at(0);
30  const float nodalPointY = cameraParam.principalPoint.at(1);
31  const float focalLengthX = cameraParam.focalLength.at(0);
32  const float focalLengthY = cameraParam.focalLength.at(1);
33 
34  cv::Mat camera_matrix = cv::Mat(3, 4, CV_64F, 0.0);
35  camera_matrix.at<double>(0, 2) = double(nodalPointX);
36  camera_matrix.at<double>(1, 2) = double(nodalPointY);
37  camera_matrix.at<double>(0, 0) = double(focalLengthX);
38  camera_matrix.at<double>(1, 1) = double(focalLengthY);
39  camera_matrix.at<double>(2, 2) = 1.0;
40 
41  return camera_matrix;
42 }
visionx::convertIvtRgbToCvGray
void convertIvtRgbToCvGray(const CByteImage &ivt_rgb, cv::Mat &cv_gray)
Definition: opencv_conversions.cpp:14
ExpressionException.h
visionx::makeCameraMatrix
cv::Mat makeCameraMatrix(const visionx::CameraParameters &cameraParams)
Definition: opencv_conversions.cpp:25
ARMARX_CHECK_EQUAL
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
Definition: ExpressionException.h:130
opencv_conversions.h