Cannot detect aruco marker

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

Here is the the rostopic list of a aruco stack running in simulation:

/aruco_detect/compressed/parameter_descriptions
/aruco_detect/compressed/parameter_updates
/aruco_detect/parameter_descriptions
/aruco_detect/parameter_updates
/fiducial_images
/fiducial_images/compressed
/fiducial_images/compressed/parameter_descriptions
/fiducial_images/compressed/parameter_updates
/fiducial_images/compressedDepth
/fiducial_images/compressedDepth/parameter_descriptions
/fiducial_images/compressedDepth/parameter_updates
/fiducial_images/theora
/fiducial_images/theora/parameter_descriptions
/fiducial_images/theora/parameter_updates
/fiducial_map
/fiducial_pose
/fiducial_slam/camera_pose
/fiducial_transforms
/fiducial_vertices
/fiducials
/ignore_fiducials
/raspicam_node/camera_info
/raspicam_node/image/compressed

These topics need to be sending data for aruco markers to work. To debug I would run rostopic echo on the topics starting with raspicam, to see where the stack is failing.

Thank you for your reply!
This issue was resolved.