Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chilitags3D.estimate(cv::Mat) Doesn't work against opencv 3.3/3.2 #95

Open
Mizerb opened this issue Dec 11, 2017 · 4 comments
Open

Chilitags3D.estimate(cv::Mat) Doesn't work against opencv 3.3/3.2 #95

Mizerb opened this issue Dec 11, 2017 · 4 comments

Comments

@Mizerb
Copy link

Mizerb commented Dec 11, 2017

When run, get an error on assertion in opencv /modules/core/src/matrix.cpp at line 2542 with:

CV_Assert( mtype == type0 || (CV_MAT_CN(mtype) == 1 && ((1 << type0) & fixedDepthMask) != 0) );

I understand these versions of opencv may not be supported, I just wanted to make sure it's written down somewhere.

@severin-lemaignan
Copy link
Member

@Mizerb I might be wrong, but it really looks like you're passing an empty image to chilitags. Can you double check your image is not empty?

@Mizerb
Copy link
Author

Mizerb commented Dec 11, 2017

@severin-lemaignan Morning, thanks for taking a look at this. I'm pretty sure the image wasn't empty. I ran cv::imshow against the mat, and it showed the correct input. Also ran chilitags::Chilitags find() on the mat, which worked successfully with opencv 3.3/3.2.

I'll check again later, and it might be something else on my end. It's that when I swapped out the opencv version it suddenly worked, I thought I finally found the issue.

@severin-lemaignan
Copy link
Member

@Mizerb ok, then it's not due to an empty image... interesting...

@MikeGameDev
Copy link

MikeGameDev commented Dec 18, 2017

Hi, I had this same problem in the "estimate3d-gui" sample. It seems that OpenCV is complaining that one matrix has a type of CV_32FC1 while the other has a type of CV_64FC1. I was able to fix this by converting both matrices to CV_64FC1 prior to calling cv::Rogrigues.

template<typename RealT>
void EstimatePose3D<RealT>::operator()(std::string const& name,
                                       std::vector<cv::Point3_<RealT> > const& objectPoints,
                                       cv::Mat_<cv::Point2f> const& imagePoints,
                                       typename Chilitags3D_<RealT>::TagPoseMap& objects)
{
    // Find the 3D pose of our tag
    cv::solvePnP(objectPoints, imagePoints,
                 mCameraMatrix, mDistCoeffs,
                 mTempRotation, mTempTranslation, false,
#ifdef OPENCV3
                 cv::SOLVEPNP_ITERATIVE);
#else
                 cv::ITERATIVE);
#endif
    //TODO: Rotation and translation vectors come out of solvePnP as double

	mTempRotation.convertTo(mTempRotation, CV_64FC1);  // ADDED THIS LINE
	mTempTranslation.convertTo(mTempTranslation, CV_64FC1); // ADDED THIS LINE

    if(mFilter3DEnabled)
        mFilter3D(name, mTempTranslation, mTempRotation);

    cv::Rodrigues(mTempRotation, mTempRotMat);

	 

   objects[name] = {
        (RealT)mTempRotMat(0,0),    (RealT)mTempRotMat(0,1),    (RealT)mTempRotMat(0,2),    (RealT)mTempTranslation.at<double>(0),
        (RealT)mTempRotMat(1,0),    (RealT)mTempRotMat(1,1),    (RealT)mTempRotMat(1,2),    (RealT)mTempTranslation.at<double>(1),
        (RealT)mTempRotMat(2,0),    (RealT)mTempRotMat(2,1),    (RealT)mTempRotMat(2,2),    (RealT)mTempTranslation.at<double>(2),
        0,                          0,                          0,                          1
    };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants