7 #ifdef NUKLEI_USE_OPENCV_LEGACY
11 #ifdef NUKLEI_USE_CIMG
20 PlaneProjection::PlaneProjection(
const std::string& opencvStereoCalibFile,
22 rotationMatrixData_(9), translationVectorData_(3),
23 intrinsicMatrixData_(9), distortionCoeffsData_(4),
26 color_[0] = color_[1] = color_[2] = 0;
27 readParameters(opencvStereoCalibFile, camNum);
30 PlaneProjection::PlaneProjection(
const PlaneProjection& pp)
32 rotationMatrixData_ = pp.rotationMatrixData_;
33 translationVectorData_ = pp.translationVectorData_;
34 intrinsicMatrixData_ = pp.intrinsicMatrixData_;
35 distortionCoeffsData_ = pp.distortionCoeffsData_;
36 for (
int i = 0; i < 3; ++i) color_[i] = pp.color_[i];
37 opacity_ = pp.opacity_;
38 #ifdef NUKLEI_USE_CIMG
39 if (pp.image_.get() != NULL)
41 image_.reset(
new image_t(pp.getImage()));
48 PlaneProjection& PlaneProjection::operator=(
const PlaneProjection& pp)
51 if (&pp ==
this)
return *
this;
52 rotationMatrixData_ = pp.rotationMatrixData_;
53 translationVectorData_ = pp.translationVectorData_;
54 intrinsicMatrixData_ = pp.intrinsicMatrixData_;
55 distortionCoeffsData_ = pp.distortionCoeffsData_;
56 for (
int i = 0; i < 3; ++i) color_[i] = pp.color_[i];
57 opacity_ = pp.opacity_;
58 #ifdef NUKLEI_USE_CIMG
59 if (pp.image_.get() != NULL)
61 image_.reset(
new image_t(pp.getImage()));
71 PlaneProjection::~PlaneProjection() {}
73 void PlaneProjection::readParameters(
const std::string& opencvStereoCalibFile,
78 #ifdef NUKLEI_USE_OPENCV_LEGACY
79 CvCalibFilter calibFilter;
80 NUKLEI_ASSERT(calibFilter.LoadCameraParams(opencvStereoCalibFile.c_str()));
81 const CvCamera* camera = calibFilter.GetCameraParams(camNum);
83 for (
int i = 0; i < 9; ++i) rotationMatrixData_.at(i) = camera->rotMatr[i];
84 for (
int i = 0; i < 3; ++i) translationVectorData_.at(i) = camera->transVect[i];
85 for (
int i = 0; i < 9; ++i) intrinsicMatrixData_.at(i) = camera->matrix[i];
86 for (
int i = 0; i < 4; ++i) distortionCoeffsData_.at(i) = camera->distortion[i];
88 NUKLEI_THROW(
"This function requires lecagy OpenCV code. It will require some work to bring it back to life.");
99 #ifdef NUKLEI_USE_CIMG
103 const unsigned p = worldPoints.size();
104 const unsigned large_p = std::max(p, 4u);
105 std::vector<double> objectPointsData(3*large_p, 0);
106 std::vector<double> imagePointsData(2*large_p, 0);
108 for (
unsigned pc = 0; pc < p; ++pc)
109 for (
unsigned i = 0; i < 3; ++i)
110 objectPointsData.at(3*pc+i) = worldPoints.at(pc)[i];
112 #ifdef NUKLEI_USE_OPENCV_LEGACY
113 CvMat object_points = cvMat(large_p, 3, CV_64FC1, &objectPointsData.front());
114 CvMat rotation_vector = cvMat(3, 3, CV_64FC1,
const_cast<double*
>(&rotationMatrixData_.front()));
115 CvMat translation_vector = cvMat(1, 3, CV_64FC1,
const_cast<double*
>(&translationVectorData_.front()));
116 CvMat intrinsic_matrix = cvMat(3, 3, CV_64FC1,
const_cast<double*
>(&intrinsicMatrixData_.front()));
117 CvMat distortion_coeffs = cvMat(1, 4, CV_64FC1,
const_cast<double*
>(&distortionCoeffsData_.front()));
118 CvMat image_points = cvMat(large_p, 2, CV_64FC1, &imagePointsData.front());
120 cvProjectPoints2(&object_points,
127 NUKLEI_THROW(
"This function requires lecagy OpenCV code. It will require some work to bring it back to life.");
130 std::vector<Vector2> imagePoints(p);
131 for (
unsigned pc = 0; pc < p; ++pc)
132 for (
unsigned i = 0; i < 2; ++i)
133 imagePoints.at(pc)[i] = imagePointsData.at(2*pc+i);
135 if (image_.get() != NULL)
138 for (std::vector<Vector2>::iterator i = imagePoints.begin();
139 i != imagePoints.end(); ++i) {
140 image_->draw_circle(i->X(), i->Y(), IMAGE_PROJECTION_RADIUS,
142 unsigned char black[] = { 0,0,0 };
143 image_->draw_circle(i->X(), i->Y(), IMAGE_PROJECTION_RADIUS,
144 black, 1,
static_cast<unsigned int>(0));
146 }
catch (cimg_library::CImgException &e) {
162 NUKLEI_TRACE_BEGIN();
163 std::vector<Vector3> worldPoints;
164 worldPoints.push_back(p);
165 std::vector<Vector2> imagePoints =
project(worldPoints);
167 return imagePoints.front();
171 void PlaneProjection::readImage(
const std::string& name)
173 NUKLEI_TRACE_BEGIN();
174 #ifdef NUKLEI_USE_CIMG
176 image_ = NUKLEI_UNIQUE_PTR<image_t>(
new image_t(name.c_str()));
177 }
catch (cimg_library::CImgException &e) {
186 void PlaneProjection::writeImage(
const std::string& name)
const
188 NUKLEI_TRACE_BEGIN();
189 #ifdef NUKLEI_USE_CIMG
192 image_->save(name.c_str());
193 }
catch (cimg_library::CImgException &e) {
202 void StereoPlaneProjection::writeStereoImage(
const std::string& name)
const
204 NUKLEI_TRACE_BEGIN();
205 #ifdef NUKLEI_USE_CIMG
207 image_t image = (left_.getImage().get_append(right_.getImage(),
'x'));
208 image.save(name.c_str());
209 }
catch (cimg_library::CImgException &e) {