相机校准opencv [英] camera calibration opencv

查看:502
本文介绍了相机校准opencv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我做一个项目做一个图像3d重建。我是校准相机的阶段,这是需要很长时间来做。但是当我编译代码并在相机前显示棋盘时,直接进入异常错误未处理。

Hi i am doing a project to do an image 3d reconstruction. I am the phase of calibrating the camera, which is taking a long time to do. But when i compile the code and display the checkerboard in front of the camera it goes straight to exception error unhandled.

当图片不在框架中时,没有错误

When picture not in frame, no error as soon as it gets in the frame, unhandled error occurs i don't know why.

我问了很多人,没有任何身体似乎可以帮助。

I have asked a lot of people, no body can seem to help.

这里是我的代码

#include <cv.h>
#include <highgui.h>
#include <vector>
#include <stdlib.h>
#include <stdio.h>

using namespace cv;
using namespace std;

int main()
{
    int numBoards = 0;
    int numCornersHor;
    int numCornersVer;

    printf("Enter number of corners along width: ");
    scanf("%d", &numCornersHor);

    printf("Enter number of corners along height: ");
    scanf("%d", &numCornersVer);

    printf("Enter number of boards: ");
    scanf("%d", &numBoards);

    int numSquares = numCornersHor * numCornersVer;
    Size board_sz = Size(numCornersHor, numCornersVer);
    VideoCapture capture = VideoCapture(0);

    vector<vector<Point3d>> object_points;
    vector<vector<Point2d>> image_points;

    vector<Point2d> corners;
    int successes=0;

    Mat image;
    Mat gray_image;
    capture >> image;

    vector<Point3d> obj;
    for(int j=0;j<numSquares;j++)
        obj.push_back(Point3d(j/numCornersHor, j%numCornersHor, 0.0f));

    while(successes<numBoards)
    {
        cvtColor(image, gray_image, CV_BGR2GRAY);

        bool found = findChessboardCorners(image, board_sz, corners, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS);

        if(found)
        {
            cornerSubPix(gray_image, corners, Size(11, 11), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1));
            drawChessboardCorners(gray_image, board_sz, corners, found);
        }

        imshow("win1", image);
        imshow("win2", gray_image);

        capture >> image;

        int key = waitKey(1);

        if(key==27)
            return 0;

        if(key==' ' && found!=0)
        {
            image_points.push_back(corners);
            object_points.push_back(obj);
            printf("Snap stored!\n");

            successes++;

            if(successes>=numBoards)
                break;
        }
    }

    Mat intrinsic = Mat(3, 3, CV_32FC1);
    Mat distCoeffs;
    vector<Mat> rvecs;
    vector<Mat> tvecs;

    intrinsic.ptr<float>(0)[0] = 1;
    intrinsic.ptr<float>(1)[1] = 1;

    calibrateCamera(object_points, image_points, image.size(), intrinsic, distCoeffs, rvecs, tvecs);

    Mat imageUndistorted;
    while(1)
    {
        capture >> image;
        undistort(image, imageUndistorted, intrinsic, distCoeffs);

        imshow("win1", image);
        imshow("win2", imageUndistorted);

        waitKey(1);
    }

    capture.release();

    return 0;
}

我在控制台上得到的错误是

the error i get on the console is

OpenCV错误:未知函数文件中的断言失败(ncorners> = 0&& amp; corner.depth()== CV_32F),文件..... \src\opencv\modules \imgproc\src\cornersubpix.cpp,第257行。

OpenCV ERROR: Assertion failed (ncorners >=0 && corners.depth() == CV_32F) in unknown function file , file .....\src\opencv\modules\imgproc\src\cornersubpix.cpp, line 257.

并且错误对话框显示

在basecalibration.exe中0x769afc16处的未处理异常:Microsoft C ++异常:cv ::内存位置0x0021f51c处的异常。

Unhandled exception at 0x769afc16 in basiccalibration.exe: Microsoft C++ exception: cv::Exception at memory location 0x0021f51c..


感谢

推荐答案

使用Point2f和Point3f代替Point2d和Point3d。请阅读断言文本。它需要一个CV_32F深度结构。

Use Point2f and Point3f instead of Point2d and Point3d. Read the assertion text please. It demands a CV_32F depth structure.

这篇关于相机校准opencv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆