JSFiddle - React, Tailwind, and code Playground
HTML
<pre>
std::vector<std::string> get_project_names();
template<typename Printable>
void print(Printable const & item);
template<typename FwdIterable, typename Predicate>
FwdIterable find_if(FwdIterable begin, FwdIterable end, Predicate pred);
</pre>
CSS
pre {
font-family: consolas;
font-size: 12px;
color: #000;
}
TypeScript
struct CamParameter
{
cv::Mat cameraMatrix;
cv::Mat distCoeffs;
};
void solvePnP(Mat& img, CamParameter camParam)
{
vector<Point3f> objectPoint;
vector<Point2f> imagePoint = findChessboard(img);
if(imagePoint.size() != CHESS_COLS*CHESS_ROWS)
return;
// createObjPoints;
for( int j = 0; j < rows; j++ )
for( int k = 0; k < cols; k++ )
objectPoints.push_back(cv::Point3f(float( k*square_size ), float( j*square_size ), 0));
cv::Mat rvecs;
cv::Mat tvecs;
cv::solvePnP(
objectPoint,
imagePoint,
camParam.cameraMatrix,
camParam.distCoeffs,
rvecs,tvecs);
cout << "rvecs\n";
cout << rvecs << endl;
cout << "tvecs\n";
cout << tvecs << endl;
vector<cv::Point3f> obj_pts;
obj_pts.push_back( Point3f(0, 0, 0));
obj_pts.push_back( Point3f(50, 0, 0));
obj_pts.push_back( Point3f(0, 50, 0));
obj_pts.push_back( Point3f(0, 0, 50));
projectPoints(
obj_pts,
rvecs,tvecs,
camParam.cameraMatrix,
camParam.distCoeffs,
imagePoint);
line(img, imagePoint.at(0), imagePoint.at(1), Scalar(0, 0, 255), 5, 8, 0);
line(img, imagePoint.at(0), imagePoint.at(2), Scalar(0, 255, 0), 5, 8, 0);
line(img, imagePoint.at(0), imagePoint.at(3), Scalar(255, 0, 0), 5, 8, 0);
}