34 #include <Structs/Structs.h>
35 #include <Image/ByteImage.h>
36 #include <Math/Math2d.h>
37 #include <Math/Math3d.h>
38 #include <Calibration/Calibration.h>
39 #include <Calibration/StereoCalibration.h>
44 static std::map<std::string, visionx::ImageType> nameToTypeMap;
47 if (nameToTypeMap.empty())
49 nameToTypeMap[
"bayer-pattern"] = visionx::eBayerPattern;
50 nameToTypeMap[
"gray-scale"] = visionx::eGrayScale;
51 nameToTypeMap[
"rgb"] = visionx::eRgb;
52 nameToTypeMap[
"float-1-channel"] = visionx::eFloat1Channel;
53 nameToTypeMap[
"float-3-channels"] = visionx::eFloat3Channels;
56 std::string lowerCaseTypeName = imageTypeName;
57 std::transform(lowerCaseTypeName.begin(), lowerCaseTypeName.end(), lowerCaseTypeName.begin(), ::tolower);
59 std::map<std::string, visionx::ImageType>::iterator nameToTypeIter = nameToTypeMap.find(lowerCaseTypeName);
61 if (nameToTypeIter == nameToTypeMap.end())
66 return nameToTypeIter->second;
74 case visionx::eBayerPattern:
75 return "bayer-pattern";
77 case visionx::eGrayScale:
83 case visionx::eFloat1Channel:
84 return "float-1-channel";
86 case visionx::eFloat3Channels:
87 return "float-3-channel";
97 static std::map<visionx::ImageType, CByteImage::ImageType> visionxTypeToIvtTypeMap;
100 if (visionxTypeToIvtTypeMap.empty())
102 visionxTypeToIvtTypeMap[visionx::eRgb] = CByteImage::eRGB24;
103 visionxTypeToIvtTypeMap[visionx::eGrayScale] = CByteImage::eGrayScale;
104 visionxTypeToIvtTypeMap[visionx::eBayerPattern] = CByteImage::eGrayScale;
107 std::map<visionx::ImageType, CByteImage::ImageType>::iterator visionxTypeToIvtTypeIter = visionxTypeToIvtTypeMap.find(visionxImageType);
109 if (visionxTypeToIvtTypeIter == visionxTypeToIvtTypeMap.end())
114 return visionxTypeToIvtTypeIter->second;
120 switch (visionxBayerPatternType)
122 case visionx::eBayerPatternBg:
123 return ::ImageProcessor::eBayerBG;
125 case visionx::eBayerPatternGb:
126 return ::ImageProcessor::eBayerGB;
128 case visionx::eBayerPatternGr:
129 return ::ImageProcessor::eBayerGR;
131 case visionx::eBayerPatternRg:
132 return ::ImageProcessor::eBayerRG;
137 return ::ImageProcessor::eBayerRG;
145 switch (imageDimension.width)
148 return CVideoCaptureInterface::eNone;
151 return CVideoCaptureInterface::e320x240;
154 return CVideoCaptureInterface::e640x480;
157 return CVideoCaptureInterface::e800x600;
160 return CVideoCaptureInterface::e768x576;
163 return CVideoCaptureInterface::e1024x768;
166 return CVideoCaptureInterface::e1280x960;
169 return CVideoCaptureInterface::e1600x1200;
172 return CVideoCaptureInterface::eNone;
177 using FrameRateRange = std::pair<float, float>;
179 static std::map<FrameRateRange, CVideoCaptureInterface::FrameRate> frameRateMap;
181 using FrameRateMapIter = std::map<FrameRateRange, CVideoCaptureInterface::FrameRate>::iterator;
183 if (frameRateMap.empty())
185 frameRateMap[FrameRateRange(0.f, 1.875f + 1.875f / 2)] = CVideoCaptureInterface::e1_875fps;
186 frameRateMap[FrameRateRange(1.875f + 1.875f / 2, 3.75f + 1.875f)] = CVideoCaptureInterface::e3_75fps;
187 frameRateMap[FrameRateRange(3.75f + 1.875f, 7.5f + 3.75f)] = CVideoCaptureInterface::e7_5fps;
188 frameRateMap[FrameRateRange(7.5f + 3.75f, 15.f + 7.5f)] = CVideoCaptureInterface::e15fps;
189 frameRateMap[FrameRateRange(15.f + 7.5f, 30.f + 15.f)] = CVideoCaptureInterface::e30fps;
190 frameRateMap[FrameRateRange(30.f + 15.f, 1024.f)] = CVideoCaptureInterface::e60fps;
193 FrameRateMapIter iter = frameRateMap.begin();
195 while (iter != frameRateMap.end())
197 if (frameRate >= iter->first.first && frameRate < iter->first.second)
212 vec2d.x = (*pVec)[0];
213 vec2d.y = (*pVec)[1];
239 ivtMat3d.r1 = mat[0][0];
240 ivtMat3d.r2 = mat[0][1];
241 ivtMat3d.r3 = mat[0][2];
242 ivtMat3d.r4 = mat[1][0];
243 ivtMat3d.r5 = mat[1][1];
244 ivtMat3d.r6 = mat[1][2];
245 ivtMat3d.r7 = mat[2][0];
246 ivtMat3d.r8 = mat[2][1];
247 ivtMat3d.r9 = mat[2][2];
255 std::vector<float> vec(2);
265 std::vector<float> vec(3);
276 std::vector<std::vector<float> > mat(3);
277 std::vector<float> rowVec(3);
279 rowVec[0] = ivtMat3d.r1;
280 rowVec[1] = ivtMat3d.r2;
281 rowVec[2] = ivtMat3d.r3;
284 rowVec = std::vector<float>(3);
285 rowVec[0] = ivtMat3d.r4;
286 rowVec[1] = ivtMat3d.r5;
287 rowVec[2] = ivtMat3d.r6;
290 rowVec = std::vector<float>(3);
291 rowVec[0] = ivtMat3d.r7;
292 rowVec[1] = ivtMat3d.r8;
293 rowVec[2] = ivtMat3d.r9;
302 CStereoCalibration* ivtStereoCalibration =
new CStereoCalibration();
304 CCalibration ivtCalibrationLeft;
305 CCalibration ivtCalibrationRight;
307 const visionx::CameraParameters& cameraParamLeft = stereoCalibration.calibrationLeft.cameraParam;
308 const visionx::CameraParameters& cameraParamRight = stereoCalibration.calibrationRight.cameraParam;
310 Mat3d R =
convert(cameraParamLeft.rotation);
315 ivtCalibrationLeft.SetCameraParameters
317 cameraParamLeft.focalLength[0],
318 cameraParamLeft.focalLength[1],
319 cameraParamLeft.principalPoint[0],
320 cameraParamLeft.principalPoint[1],
321 cameraParamLeft.distortion[0],
322 cameraParamLeft.distortion[1],
323 cameraParamLeft.distortion[2],
324 cameraParamLeft.distortion[3],
327 cameraParamLeft.width,
328 cameraParamLeft.height
331 R =
convert(cameraParamRight.rotation);
332 t =
convert(cameraParamRight.translation);
337 ivtCalibrationRight.SetCameraParameters
339 cameraParamRight.focalLength[0],
340 cameraParamRight.focalLength[1],
341 cameraParamRight.principalPoint[0],
342 cameraParamRight.principalPoint[1],
343 cameraParamRight.distortion[0],
344 cameraParamRight.distortion[1],
345 cameraParamRight.distortion[2],
346 cameraParamRight.distortion[3],
349 cameraParamRight.width,
350 cameraParamRight.height
353 ivtStereoCalibration->SetSingleCalibrations(ivtCalibrationLeft, ivtCalibrationRight);
355 ivtStereoCalibration->rectificationHomographyLeft =
convert(stereoCalibration.rectificationHomographyLeft);
356 ivtStereoCalibration->rectificationHomographyRight =
convert(stereoCalibration.rectificationHomographyRight);
358 return ivtStereoCalibration;
365 CCalibration* ivtCalibration =
new CCalibration();
367 const visionx::CameraParameters& cameraParam = calibration.cameraParam;
369 Mat3d R =
convert(cameraParam.rotation);
372 ivtCalibration->SetCameraParameters
374 cameraParam.focalLength[0],
375 cameraParam.focalLength[1],
376 cameraParam.principalPoint[0],
377 cameraParam.principalPoint[1],
378 cameraParam.distortion[0],
379 cameraParam.distortion[1],
380 cameraParam.distortion[2],
381 cameraParam.distortion[3],
388 return ivtCalibration;
393 visionx::StereoCalibration stereoCalibration;
395 const CCalibration::CCameraParameters& ivtCalibParamLeft = ivtStereoCalibration.GetLeftCalibration()->GetCameraParameters();
396 const CCalibration::CCameraParameters& ivtCalibParamRight = ivtStereoCalibration.GetRightCalibration()->GetCameraParameters();
398 visionx::CameraParameters& cameraParamLeft = stereoCalibration.calibrationLeft.cameraParam;
399 visionx::CameraParameters& cameraParamRight = stereoCalibration.calibrationRight.cameraParam;
402 cameraParamLeft.width = ivtCalibParamLeft.width;
403 cameraParamLeft.height = ivtCalibParamLeft.height;
405 cameraParamLeft.principalPoint =
convert(ivtCalibParamLeft.principalPoint);
406 cameraParamLeft.focalLength =
convert(ivtCalibParamLeft.focalLength);
407 cameraParamLeft.rotation =
convert(ivtCalibParamLeft.rotation);
408 cameraParamLeft.translation =
convert(ivtCalibParamLeft.translation);
410 cameraParamLeft.distortion.push_back(ivtCalibParamLeft.distortion[0]);
411 cameraParamLeft.distortion.push_back(ivtCalibParamLeft.distortion[1]);
412 cameraParamLeft.distortion.push_back(ivtCalibParamLeft.distortion[2]);
413 cameraParamLeft.distortion.push_back(ivtCalibParamLeft.distortion[3]);
416 cameraParamRight.width = ivtCalibParamRight.width;
417 cameraParamRight.height = ivtCalibParamRight.height;
419 cameraParamRight.principalPoint =
convert(ivtCalibParamRight.principalPoint);
420 cameraParamRight.focalLength =
convert(ivtCalibParamRight.focalLength);
421 cameraParamRight.rotation =
convert(ivtCalibParamRight.rotation);
422 cameraParamRight.translation =
convert(ivtCalibParamRight.translation);
424 cameraParamRight.distortion.push_back(ivtCalibParamRight.distortion[0]);
425 cameraParamRight.distortion.push_back(ivtCalibParamRight.distortion[1]);
426 cameraParamRight.distortion.push_back(ivtCalibParamRight.distortion[2]);
427 cameraParamRight.distortion.push_back(ivtCalibParamRight.distortion[3]);
429 stereoCalibration.rectificationHomographyLeft =
convert(ivtStereoCalibration.rectificationHomographyLeft);
430 stereoCalibration.rectificationHomographyRight =
convert(ivtStereoCalibration.rectificationHomographyRight);
432 return stereoCalibration;
438 visionx::MonocularCalibration calibration;
439 const CCalibration::CCameraParameters& ivtCalibParam = ivtCalibration.GetCameraParameters();
441 calibration.cameraParam.width = ivtCalibParam.width;
442 calibration.cameraParam.height = ivtCalibParam.height;
444 calibration.cameraParam.principalPoint =
convert(ivtCalibParam.principalPoint);
445 calibration.cameraParam.focalLength =
convert(ivtCalibParam.focalLength);
446 calibration.cameraParam.rotation =
convert(ivtCalibParam.rotation);
447 calibration.cameraParam.translation =
convert(ivtCalibParam.translation);
449 calibration.cameraParam.distortion.push_back(ivtCalibParam.distortion[0]);
450 calibration.cameraParam.distortion.push_back(ivtCalibParam.distortion[1]);
451 calibration.cameraParam.distortion.push_back(ivtCalibParam.distortion[2]);
452 calibration.cameraParam.distortion.push_back(ivtCalibParam.distortion[3]);
460 visionx::types::Region region;
463 region.nPixels = ivtRegion.nPixels;
465 region.minX = ivtRegion.min_x;
466 region.maxX = ivtRegion.max_x;
467 region.minY = ivtRegion.min_y;
468 region.maxY = ivtRegion.max_y;
470 region.ratio = ivtRegion.ratio;
483 ivtRegion.nPixels = region.nPixels;
485 ivtRegion.min_x = region.minX;
486 ivtRegion.max_x = region.maxX;
487 ivtRegion.min_y = region.minY;
488 ivtRegion.max_y = region.maxY;
490 ivtRegion.ratio = region.ratio;
500 return (visionx::types::ObjectColor) ivtObjectColor;
506 return (ObjectColor) objectColor;
512 return (visionx::types::ObjectType) ivtObjectType;
518 return (ObjectType) objectType;
524 visionx::types::Transformation3d transformation3d;
529 return transformation3d;
535 Transformation3d ivtTransformation3d;
540 return ivtTransformation3d;
546 Object3DEntry ivtObject3DEntry;
548 ivtObject3DEntry.region_left =
convert(object3DEntry.regionLeft);
549 ivtObject3DEntry.region_right =
convert(object3DEntry.regionRight);
550 ivtObject3DEntry.region_id_left = object3DEntry.regionIdLeft;
551 ivtObject3DEntry.region_id_right = object3DEntry.regionIdRight;
552 ivtObject3DEntry.type =
convert(object3DEntry.type);
553 ivtObject3DEntry.color =
convert(object3DEntry.color);
554 ivtObject3DEntry.pose =
convert(object3DEntry.pose);
555 ivtObject3DEntry.world_point =
convert(object3DEntry.worldPoint);
556 ivtObject3DEntry.orientation =
convert(object3DEntry.orientation);
557 ivtObject3DEntry.sName =
"";
558 ivtObject3DEntry.sName += object3DEntry.name;
559 ivtObject3DEntry.sOivFilePath =
"";
561 ivtObject3DEntry.data =
nullptr;
562 ivtObject3DEntry.class_id = object3DEntry.classId;
563 ivtObject3DEntry.quality = object3DEntry.quality;
564 ivtObject3DEntry.quality2 = object3DEntry .quality2;
566 return ivtObject3DEntry;
572 visionx::types::Object3DEntry object3DEntry;
574 object3DEntry.regionLeft =
convert(ivtObject3DEntry.region_left);
575 object3DEntry.regionRight =
convert(ivtObject3DEntry.region_right);
576 object3DEntry.regionIdLeft = ivtObject3DEntry.region_id_left;
577 object3DEntry.regionIdRight = ivtObject3DEntry.region_id_right;
578 object3DEntry.type =
convert(ivtObject3DEntry.type);
579 object3DEntry.color =
convert(ivtObject3DEntry.color);
580 object3DEntry.pose =
convert(ivtObject3DEntry.pose);
581 object3DEntry.worldPoint =
convert(ivtObject3DEntry.world_point);
582 object3DEntry.orientation =
convert(ivtObject3DEntry.orientation);
583 object3DEntry.name =
"";
584 object3DEntry.name += ivtObject3DEntry.sName;
587 object3DEntry.classId = ivtObject3DEntry.class_id;
588 object3DEntry.quality = ivtObject3DEntry.quality;
589 object3DEntry.quality2 = ivtObject3DEntry.quality2;
591 return object3DEntry;
596 Object3DList ivtObject3DList(object3DList.size());
598 visionx::types::Object3DList::const_iterator iter = object3DList.begin();
602 while (iter != object3DList.end())
604 ivtObject3DList[i] =
convert(*iter);
609 return ivtObject3DList;
615 visionx::types::Object3DList object3DList(ivtObject3DList.size());
617 Object3DList::const_iterator iter = ivtObject3DList.begin();
621 while (iter != ivtObject3DList.end())
623 object3DList[i] =
convert(*iter);
650 Eigen::Vector3f result(
v.x,
v.y,
v.z);
657 visionx::types::Vec res;
658 res.resize(
v.rows());
659 for (
int i = 0; i <
v.rows(); i++)
669 res.resize(
v.size());
670 for (
int i= 0; i <
v.size(); i++){
679 visionx::types::Mat res;
680 res.resize(m.cols());
681 for (
int i = 0; i < m.cols(); i++)
683 visionx::types::Vec
v;
684 Eigen::VectorXf vec = m.block(0, i, m.rows(), 1);
694 return Eigen::MatrixXf();
696 const size_t rows = m[0].size();
697 const size_t cols = m.size();
699 Eigen::MatrixXf res(rows, cols);
701 for (
size_t col = 0; col < cols; ++col) {
702 visionx::types::Vec
v = m[col];