2

I am getting this error while cv::aruco::estimatePoseCharucoBoard. but it works fine when I do cv::aruco::estimatePoseSingleMarkers. I have also tried to change the image channels CV_8UC1 to CV_8UC3 and CV_8UC4. when I make it 4 it asks for 1 or 3. so I sticked to greyscale as detect markers works fine.

2023-01-17 12:45:50.581655+0530 cvAruco[16006:3332341] Metal GPU Frame Capture Enabled
2023-01-17 12:45:50.582330+0530 cvAruco[16006:3332341] Metal API Validation Enabled
libc++abi: terminating with uncaught exception of type cv::Exception: OpenCV(4.1.2) /Users/5dof/Downloads/opencv/opencv-4.1.2/modules/core/src/copy.cpp:254: error: (-215:Assertion failed) channels() == CV_MAT_CN(dtype) in function 'copyTo'

terminating with uncaught exception of type cv::Exception: OpenCV(4.1.2) /Users/5dof/Downloads/opencv/opencv-4.1.2/modules/core/src/copy.cpp:254: error: (-215:Assertion failed) channels() == CV_MAT_CN(dtype) in function 'copyTo'

Posting the entire code so that you can help me out. following is the code:

static void detect(cv::Ptr<cv::aruco::Dictionary> &dictionary,std::vector<std::vector<cv::Point2f> > &corners, std::vector<int> &ids, std::vector<cv::Point2f> &charucoCorners,std::vector<int> &charucoIds, cv::Ptr<cv::aruco::CharucoBoard> &charucoBoard, CVPixelBufferRef pixelBuffer) {
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
void *baseaddress = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0);
CGFloat width = CVPixelBufferGetWidth(pixelBuffer);
CGFloat height = CVPixelBufferGetHeight(pixelBuffer);
cv::Mat greymat(height, width, CV_8UC1, baseaddress, 0); //CV_8UC1   
cv::aruco::detectMarkers(greymat,dictionary,corners,ids);
if(ids.size() > 0)
{
    cv::aruco::interpolateCornersCharuco(corners, ids, greymat, charucoBoard, charucoCorners, charucoIds);
}
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);

}

+(NSMutableArray *) estimatePose:(CVPixelBufferRef)pixelBuffer withIntrinsics:(matrix_float3x3)intrinsics andMarkerSize:(Float64)markerSize {
cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
cv::Ptr<cv::aruco::CharucoBoard> charucoBoard = cv::aruco::CharucoBoard::create(5, 7, 0.03636f, 0.02951f, dictionary);
std::vector<int> ids;
std::vector<cv::Point2f> charucoCorners;
std::vector<int> charucoIds;
std::vector<std::vector<cv::Point2f>> corners;
detect(dictionary, corners, ids,charucoCorners, charucoIds, charucoBoard, pixelBuffer);
NSMutableArray *arrayMatrix = [NSMutableArray new];
if(ids.size() == 0) {
    return arrayMatrix;
}

cv::Mat intrinMat(3,3,CV_64F);
intrinMat.at<Float64>(0,0) = intrinsics.columns[0][0];
intrinMat.at<Float64>(0,1) = intrinsics.columns[1][0];
intrinMat.at<Float64>(0,2) = intrinsics.columns[2][0];
intrinMat.at<Float64>(1,0) = intrinsics.columns[0][1];
intrinMat.at<Float64>(1,1) = intrinsics.columns[1][1];
intrinMat.at<Float64>(1,2) = intrinsics.columns[2][1];
intrinMat.at<Float64>(2,0) = intrinsics.columns[0][2];
intrinMat.at<Float64>(2,1) = intrinsics.columns[1][2];
intrinMat.at<Float64>(2,2) = intrinsics.columns[2][2];

std::vector<cv::Vec3d> rvecs, tvecs;
cv::Mat distCoeffs = cv::Mat::zeros(8, 1, CV_64F);


    
if(charucoIds.size() > 0)
{
    cv::aruco::estimatePoseCharucoBoard(charucoCorners, charucoIds, charucoBoard, intrinMat, distCoeffs, rvecs, tvecs);
}
else
    cv::aruco::estimatePoseSingleMarkers(corners, markerSize, intrinMat, distCoeffs, rvecs, tvecs);

NSLog(@"found: rvecs.size(): %lu", rvecs.size());
cv::Mat rotMat, tranMat;
for (int i = 0; i < rvecs.size(); i++) {
    cv::Rodrigues(rvecs[i], rotMat);
    cv::Mat extrinsics = rotateRodriques(rotMat, tvecs[i]);
    SCNMatrix4 scnMatrix = [ArucoCV transformToSceneKitMatrix:extrinsics];
    SKWorldTransform *transform = [SKWorldTransform new];
    transform.arucoId = ids[i];
    transform.transform = scnMatrix;
    [arrayMatrix addObject:transform];
}

return arrayMatrix;

}

I have been stuck here since 3 days, please let me know what I am missing

pmdj
  • 22,018
  • 3
  • 52
  • 103
geek
  • 794
  • 3
  • 16
  • 41
  • try changing CV_64F to CV_64FC1 or CV_64FC3 – udi Jan 17 '23 at 07:39
  • converting to CV_64FC3 throwing this error:terminating with uncaught exception of type cv::Exception: OpenCV(4.1.2) /Users/5dof/Downloads/opencv/opencv-4.1.2/modules/calib3d/src/undistort.dispatch.cpp:297: error: (-215:Assertion failed) CV_IS_MAT(_distCoeffs) && (_distCoeffs->rows == 1 || _distCoeffs->cols == 1) && (_distCoeffs->rows*_distCoeffs->cols == 4 || _distCoeffs->rows*_distCoeffs->cols == 5 || _distCoeffs->rows*_distCoeffs->cols == 8 || _distCoeffs->rows*_distCoeffs->cols == 12 || _distCoeffs->rows*_distCoeffs->cols == 14) in function 'cvUndistortPointsInternal' – geek Jan 17 '23 at 07:54
  • @udi: CV_64FC1 is the same error : terminating with uncaught exception of type cv::Exception: OpenCV(4.1.2) /Users/5dof/Downloads/opencv/opencv-4.1.2/modules/core/src/copy.cpp:254: error: (-215:Assertion failed) channels() == CV_MAT_CN(dtype) in function 'copyTo' – geek Jan 17 '23 at 07:56
  • 1
    traceback/stacktrace required. your code contains no `copyTo`, so something you call must be using it. figure out what that is. -- [mre] required. please make sure your code formatting shows up properly in the post. [edit] your post instead of pasting unformatted code into a comment. and DO NOT use v4.1.2 of OpenCV, that's very outdated. – Christoph Rackwitz Jan 17 '23 at 17:02

0 Answers0