Getting matrix_wrap.cpp:1393: error: (-215:Assertion failed)

Till yesterday I was using Opencv 4.10. I tried with 4.8 and got same result. Today I tried with 4.5.3 and it worked perfectly fine though the code is a bit different.

// For OpenCV version: 4.5.3:
int main() {
    std::cout << "OpenCV version: " << CV_VERSION << std::endl;

    // read image
    cv::Mat imgCopy, img = cv::imread("/tmp/qcodes.png");

    std::cout << "Converting to Gray scale! " << std::endl;
    cvtColor(img, imgCopy, cv::COLOR_BGR2GRAY);
    std::vector<int> ids;
    std::vector<std::vector<cv::Point2f>> corners;
    cv::Ptr<cv::aruco::Dictionary> dictionary =
        cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);

    cv::aruco::detectMarkers(imgCopy, dictionary, corners, ids);
    if (ids.size() > 0) {
        cv::aruco::drawDetectedMarkers(imgCopy, corners, ids);
    }

    cv::imshow("Image", imgCopy);

    cv::waitKey(0);
    cv::destroyAllWindows();
    img.release();
    imgCopy.release();
}