Hello,
I tried aruco marker with following code.
But markerIds.size() keeps zero. However marker is in front of camera.
Camera module works normally maybe.
To use aruco maker, I installed ros-noetic-fiducials.
And aruco marker was generated by
$ rosrun aruco_detect create_markers.py 100 112 fiducials.pdf
Could someone advise me on what the problem is?
Are few warning of GStreamer related to this problem?
******************** The code *****************************************
#include
#include
#include <opencv2/opencv.hpp>
#include <opencv2/aruco.hpp>
using namespace std;
using namespace cv;
using namespace aruco;
int main(int argc, char** argv)
{
VideoCapture cap(0);
cap.set(cv::CAP_PROP_FRAME_WIDTH, 640);
cap.set(cv::CAP_PROP_FRAME_HEIGHT, 480);
Ptr<Dictionary> dictionary = getPredefinedDictionary(DICT_4X4_50);
//reading camera calibration data
cv::Mat cameraMatrix, distCoeffs;
cv::FileStorage fs("calibration.xml", cv::FileStorage::READ);
fs["camera_matrix"] >> cameraMatrix;
fs["dist_coeffs"] >> distCoeffs;
while (true) {
Mat frame;
cap.read(frame);
vector<int> markerIds;
vector<vector<Point2f>> markerCorners;
detectMarkers(frame, dictionary, markerCorners, markerIds);
if (markerIds.size() > 0) {
drawDetectedMarkers(frame, markerCorners, markerIds);
vector<Vec3d> rvecs, tvecs;
estimatePoseSingleMarkers(markerCorners, 0.05, cameraMatrix, distCoeffs, rvecs, tvecs);
for (int i = 0; i < markerIds.size(); i++) {
cout << "Marker ID: " << markerIds[i] << endl;
cout << "Translation: " << tvecs[i] << endl;
cout << "Rotation: " << rvecs[i] << endl;
}
}
imshow("ArUco Marker Detection", frame);
waitKey(1);
}
return 0;
}
*************** Warning *************************
[ WARN:0] global …/modules/videoio/src/cap_gstreamer.cpp (1758) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Failed to allocate required memory.
[ WARN:0] global …/modules/videoio/src/cap_gstreamer.cpp (888) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global …/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created