22 #include <linux/videodev2.h>
25 #include <Eigen/Geometry>
26 #include <opencv2/calib3d/calib3d.hpp>
27 #include <opencv2/core/eigen.hpp>
150 { itsIMU = addSubComponent<jevois::ICM20948>(
"imu"); }
166 static cv::Mat itsCamMatrix = cv::Mat();
167 static cv::Mat itsDistCoeffs = cv::Mat();
168 if (itsCamMatrix.empty())
170 std::string
const cpf = std::string(JEVOIS_SHARE_PATH) +
"/camera/calibration" +
173 cv::FileStorage fs(cpf, cv::FileStorage::READ);
176 fs[
"camera_matrix"] >> itsCamMatrix;
177 fs[
"distortion_coefficients"] >> itsDistCoeffs;
178 LINFO(
"Loaded camera calibration from " << cpf);
180 else LERROR(
"Failed to read camera parameters from file [" << cpf <<
"] -- IGNORED");
187 memcpy(outimg.
pixelsw<
void>(), inimg.
pixels<
void>(), std::min(inimg.
buf->length(), outimg.
buf->length()));
194 static long step_ts = 0;
195 static long steps = 0;
196 static std::vector<std::string> bac;
197 static cv::Vec3d rvec(0.0, 0.0, 0.0);
198 static cv::Vec3d tvec(0.0, 0.0, 0.5);
199 float const hsz = 0.075F;
200 static int pickup = 0;
201 long quat[3] = { 0, 0, 0 };
204 bool has_accel =
false, has_gyro =
false, has_cpass =
false;
209 while (itsIMU->dataReady())
211 d = itsIMU->getDMP(); ++npkt;
258 if (qtype.empty() ==
false)
263 q.w() = std::sqrt(1.0 -
q.squaredNorm());
268 3,
h + 3, jevois::yuyv::White);
272 Eigen::Matrix3d eig_rmat =
q.toRotationMatrix();
273 cv::Mat rmat(3, 3, CV_64FC1); cv::eigen2cv(eig_rmat, rmat);
274 cv::Rodrigues(rmat, rvec);
277 std::vector<cv::Point3f> axisPoints;
278 axisPoints.push_back(cv::Point3f(0.0
F, 0.0
F, 0.0
F));
279 axisPoints.push_back(cv::Point3f(hsz * 1.5
F, 0.0
F, 0.0
F));
280 axisPoints.push_back(cv::Point3f(0.0
F, hsz * 1.5
F, 0.0
F));
281 axisPoints.push_back(cv::Point3f(0.0
F, 0.0
F, hsz * 1.5
F));
282 axisPoints.push_back(cv::Point3f(hsz * 1.55
F, 0.0
F, 0.0
F));
283 axisPoints.push_back(cv::Point3f(0.0
F, hsz * 1.55
F, 0.0
F));
284 axisPoints.push_back(cv::Point3f(0.0
F, 0.0
F, hsz * 1.55
F));
286 std::vector<cv::Point2f> imagePoints;
287 cv::projectPoints(axisPoints, rvec, tvec, itsCamMatrix, itsDistCoeffs, imagePoints);
291 int(imagePoints[1].x + 0.5
F),
int(imagePoints[1].y + 0.5
F),
292 2, jevois::yuyv::MedPurple);
297 int(imagePoints[2].x + 0.5
F),
int(imagePoints[2].y + 0.5
F),
298 2, jevois::yuyv::MedGreen);
303 int(imagePoints[3].x + 0.5
F),
int(imagePoints[3].y + 0.5
F),
304 2, jevois::yuyv::MedGrey);
309 std::vector<cv::Point3f> cubePoints;
310 cubePoints.push_back(cv::Point3f(-hsz, -hsz, -hsz));
311 cubePoints.push_back(cv::Point3f(hsz, -hsz, -hsz));
312 cubePoints.push_back(cv::Point3f(hsz, hsz, -hsz));
313 cubePoints.push_back(cv::Point3f(-hsz, hsz, -hsz));
314 cubePoints.push_back(cv::Point3f(-hsz, -hsz, hsz));
315 cubePoints.push_back(cv::Point3f(hsz, -hsz, hsz));
316 cubePoints.push_back(cv::Point3f(hsz, hsz, hsz));
317 cubePoints.push_back(cv::Point3f(-hsz, hsz, hsz));
319 std::vector<cv::Point2f> cuf;
320 cv::projectPoints(cubePoints, rvec, tvec, itsCamMatrix, itsDistCoeffs, cuf);
323 std::vector<cv::Point> cu;
324 for (
auto const & p : cuf) cu.push_back(cv::Point(
int(p.x + 0.5F),
int(p.y + 0.5F)));
343 3,
h + 15, jevois::yuyv::White);
347 w - 11*6,
h + 15, jevois::yuyv::White);
356 if (has_accel || has_gyro || has_cpass)
365 dd.
ax(), dd.
ay(), dd.
az()),
366 333,
h + 3, jevois::yuyv::White);
370 dd.
gx(), dd.
gy(), dd.
gz()),
371 3,
h + 27, jevois::yuyv::White);
375 dd.
mx(), dd.
my(), dd.
mz()),
376 333,
h + 27, jevois::yuyv::White);
383 if (pickup > 0) --pickup;
390 std::shared_ptr<jevois::ICM20948> itsIMU;