Ask Your Question
0

cv::calibrateCamera calling _rvecs.create(nimages, 1, CV_64FC3) is failed

asked 2016-03-07 07:48:03 -0600

Chester gravatar image

updated 2016-03-07 07:49:31 -0600

I use the following code to test cv::calibrateCamera, but there is an fatal error, cv::calibrateCamera calling _rvecs.create(nimages, 1, CV_64FC3) is failed. Curiously, the same code can run correct on Qt+MinGW platform, but can cause an error on VS2015 platform. Why? My openCV version is 3.1.0. Thank you!

 void testCalibrate(void) 
    {
        std::vector<std::vector<cv::Point3f>> object_points_xyz_;
        std::vector<std::vector<cv::Point2f>> image_points_xy_;

        int rows = 1024;
        int cols = 1280;

        dlp::Image temp_calibration_image;
        char buf[512];
        cv::Mat calibration_image_cv;
        cv::Mat pointBuf;
        std::vector<cv::Point2f>  board_feature_locations_xy;
        cv::Size board_feature_size(8, 6);

        // Values are added during Setup() method. Assumes board is planar and that z = 0.
        std::vector<cv::Point3f> calibration_board_feature_points_xyz_;

        // Clear pattern points in case it has already been setup
        calibration_board_feature_points_xyz_.clear();

        // Assume that the first feature is located a 0,0 because the chessboard
        // is in real space and has no direct relationship to the camera sensor
        for (unsigned int iRow = 0; iRow < 6; iRow++) {
            for (unsigned int iCol = 0; iCol < 8; iCol++) {
                float x_pos = iCol * 5.555556; //this->board_column_distance_
                float y_pos = iRow * 6.071429; //this->board_row_distance_.Get(); 

                cv::Point3f feature_point = cv::Point3f(x_pos, y_pos, 0.0f);
                calibration_board_feature_points_xyz_.push_back(feature_point);
            }
        }



        for (int i = 0; i < 10; i++)
        {
            sprintf(buf, "F:\\calibration_camera\\camera_only_calibration_capture_%d.bmp", i + 1);
            temp_calibration_image.Load(buf);

            if (temp_calibration_image.ConvertToMonochrome().hasErrors())
                return;

            // Convert dlp::Image to cv::Mat
            temp_calibration_image.GetOpenCVData(&calibration_image_cv);

            // Look for the chessboard (checkerboard corners
            if (cv::findChessboardCorners(calibration_image_cv,
                board_feature_size,
                pointBuf,
                CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS)) {

                // Board was found. Refine the corner positions
                // NOTE : Many of these arguments would be good parameter settings for calibration
                cv::cornerSubPix(calibration_image_cv,
                    pointBuf,
                    cv::Size(11, 11),
                    cv::Size(-1, -1),
                    cv::TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1));

                board_feature_locations_xy.assign((cv::Point2f*)pointBuf.datastart, (cv::Point2f*)pointBuf.dataend);

                // Add this calibration image's corners to the list
                image_points_xy_.push_back(board_feature_locations_xy);
                object_points_xyz_.push_back(calibration_board_feature_points_xyz_);

                //clear
                temp_calibration_image.Clear();
                calibration_image_cv.release();
                pointBuf.release();
                board_feature_locations_xy.clear();
            }
        }

        // Create calibration flags
        int cv_calibration_flags = 0;

        // Determine which calibration data should be updated
        cv::Mat intrinsic;
        cv::Mat distortion;
        cv::Mat extrinsic;
        cv::Mat homography;

    //      std::vector<std::vector<cv::Point3f>> object_points_xyz_;
    //      std::vector<std::vector<cv::Point2f>> image_points_xy_;

        intrinsic.create(3, 3, CV_64FC1); //CV_INTRINSIC_SETUP
        intrinsic.setTo(cv::Scalar(0));

        distortion.create(5, 1, CV_64FC1);
        distortion.setTo(cv::Scalar(0));

        extrinsic.create(2, 3, CV_64FC1);
        extrinsic.setTo(cv::Scalar(0));

        homography.create(3, 3, CV_64FC1);
        homography.setTo(cv::Scalar(0));



        // Calibrate the camera
        double               reproj_error;
        std::vector<cv::Mat> rotation_vector;
        std::vector<cv::Mat> translation_vector;
        /// cv::Mat rotation;
        /// cv::Mat translation;
        cv::Size calibration_model_size = cv::Size(8, 6);

        // Perform calibration
        reproj_error = cv::calibrateCamera(object_points_xyz_,    // chessboard corners coordinate x, y, z = 0 in mm
            image_points_xy_,      // chessboard corners coordinate x, y in camera pixels
            calibration_model_size,
            intrinsic,                   // in pixels
            distortion,                  // in pixels
            rotation_vector,             // unitless direction angle of camera to calibration board
            translation_vector,          // translation vector x,y,z for each calibration board in mm
            cv_calibration_flags);

        // Copy the rotation and translation vector to the extrinsic calibration data object.
        // Only copy the vectors from the first pattern board ...
(more)
edit retag flag offensive close merge delete

Comments

" is failed." -- means what, exactly ?

berak gravatar imageberak ( 2016-03-07 07:50:09 -0600 )edit

It causes an fatal error. 0x000007FED2255F3C (opencv_core310.dll) in (located in GPURenderingApp.exe) caused by the exception: 0xC0000005: access to the location of the 0xFFFFFFFFFFFFFFFF read access conflict.

located in the file e:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xmemory0

// TEMPLATE FUNCTION _Destroy_range template<class _alloc=""> inline void _Destroy_range(typename _Alloc::pointer _First, typename _Alloc::pointer _Last, _Alloc& _Al, _Nonscalar_ptr_iterator_tag) { // destroy [_First, _Last), arbitrary type for (; _First != _Last; ++_First) _Al.destroy(_STD addressof(*_First)); }

Chester gravatar imageChester ( 2016-03-07 07:56:39 -0600 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2016-03-07 07:59:21 -0600

berak gravatar image

sounds more like a linker issue. did you link opencv_core310.dll (the release version) against a debug build ?

edit flag offensive delete link more

Comments

You are right!!! Now I have solved this problem using openCV debug version! Thank you!!!

Chester gravatar imageChester ( 2016-03-07 08:23:01 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-03-07 07:48:03 -0600

Seen: 221 times

Last updated: Mar 07 '16