- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
几天来,我一直在用棋盘示例进行相机校准。一切都很好(找到并显示角,然后馈送到数组)直到我调用最终函数 calibrateCamera。比我得到断言错误:
OpenCV 错误:calibrateCamera 断言失败(nimages > 0),文件/home/ig/Downloads/opencv-2.4.8/modules/calib3d/src/calibration.cpp,第 3415 行
这是经典代码:
#include <iostream>
#include <fstream>
#include <vector>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
VideoCapture captR(0); // open the video camera no. 0 (RIGHT)
if (!captR.isOpened()) // if not success, exit program
{
cout << "Cannot open the video cam 0" << endl;
return -1;
}
namedWindow("MyVideo (RIGHT)",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
namedWindow("Grayscale",CV_WINDOW_AUTOSIZE); //create a window called "Grayscale"
int a = 0; // Frame counter
int numCornersHor = 7; // Chessboard dimensions
int numCornersVer = 5;
int numSquares = numCornersHor * numCornersVer;
Size boardSize = Size(numCornersHor, numCornersVer);
Mat frameR;
// Mat frameL;
Mat gray_frame;
vector<Point3f> obj;
vector<Point2f> corners; // output vectors of image points
for (int i=0; i<boardSize.height; i++) {
for (int j=0; j<boardSize.width; j++) {
obj.push_back(Point3f(i, j, 0.0f));
}
}
while (1){
int key = waitKey(30);
bool bCaptSuccessR = captR.read(frameR); // read a new frame from video
if (!bCaptSuccessR) //if capture not succeded, break loop
{
cout << "Cannot read a frame from video stream" << endl;
break;
}
vector<vector<Point3f> > object_points;
vector<vector<Point2f> > image_points;
// make grayscale frame version for conerSubPix
cvtColor(frameR, gray_frame, CV_BGR2GRAY);
// Get the chessboard corners
bool found = findChessboardCorners(frameR, boardSize, corners);
if (found) {
// Increase accuracy by subpixels
cornerSubPix(gray_frame, corners, Size(11, 11), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1));
drawChessboardCorners(gray_frame, boardSize, corners, found);
imshow("Grayscale", gray_frame);
////////////////////////////////////////////
if(key==32){ // Save good found by pressing [space]
image_points.push_back(corners);
object_points.push_back(obj);
cout << "Captured good calibration image, No " << a << endl;
cout << "corners: " << corners << endl;
//cout << "obj: " << obj << endl;
a++;
}
}
imshow("MyVideo (RIGHT)", frameR); //show right webcam frame in "MyVideo" window
if (key == 27) { //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
cout << "esc key is pressed by user" << endl;
break;
}
if (key == 115){ // If 'S' key pressed begin calibration
//////////// BEGIN CALIBRATION ////////////////////////
cout << "Callibration started..." << endl;
Mat cameraMatrix = Mat(3, 3, CV_64F);
cameraMatrix.at<double>(0,0) = 1.0;
Mat distCoeffs;
distCoeffs = Mat::zeros(8, 1, CV_64F);
vector<Mat> rvecs;
vector<Mat> tvecs;
Size imageSize = frameR.size();
calibrateCamera(object_points, image_points, imageSize, cameraMatrix, distCoeffs, rvecs, tvecs);
cout << "Callibration ended." << endl;
}//callibration
}
captR.release();
return 0;
}
这是带有行号的 OpenCV 文件摘录:
3400 double cv::calibrateCamera( InputArrayOfArrays _objectPoints,
3401 InputArrayOfArrays _imagePoints,
3402 Size imageSize, InputOutputArray _cameraMatrix, InputOutputArray _distCoeffs,
3403 OutputArrayOfArrays _rvecs, OutputArrayOfArrays _tvecs, int flags, TermCriteria criteria )
3404 {
3405 int rtype = CV_64F;
3406 Mat cameraMatrix = _cameraMatrix.getMat();
3407 cameraMatrix = prepareCameraMatrix(cameraMatrix, rtype);
3408 Mat distCoeffs = _distCoeffs.getMat();
3409 distCoeffs = prepareDistCoeffs(distCoeffs, rtype);
3410 if( !(flags & CALIB_RATIONAL_MODEL) )
3411 distCoeffs = distCoeffs.rows == 1 ? distCoeffs.colRange(0, 5) : distCoeffs.rowRange(0, 5);
3412
3413 int i;
3414 size_t nimages = _objectPoints.total();
3415 CV_Assert( nimages > 0 );
3416 Mat objPt, imgPt, npoints, rvecM((int)nimages, 3, CV_64FC1), tvecM((int)nimages, 3, CV_64FC1);
3417 collectCalibrationData( _objectPoints, _imagePoints, noArray(),
3418 objPt, imgPt, 0, npoints );
3419 CvMat c_objPt = objPt, c_imgPt = imgPt, c_npoints = npoints;
3420 CvMat c_cameraMatrix = cameraMatrix, c_distCoeffs = distCoeffs;
3421 CvMat c_rvecM = rvecM, c_tvecM = tvecM;
3422
3423 double reprojErr = cvCalibrateCamera2(&c_objPt, &c_imgPt, &c_npoints, imageSize,
3424 &c_cameraMatrix, &c_distCoeffs, &c_rvecM,
3425 &c_tvecM, flags, criteria );
3426
3427 bool rvecs_needed = _rvecs.needed(), tvecs_needed = _tvecs.needed();
3428
3429 if( rvecs_needed )
3430 _rvecs.create((int)nimages, 1, CV_64FC3);
3431 if( tvecs_needed )
3432 _tvecs.create((int)nimages, 1, CV_64FC3);
3433
使用 Linux Ubuntu 12.04、OpenCV 2.4.8、gcc 4.6.3、Eclipse,...
最佳答案
您正在 while
循环内声明 object_points
和 image_points
,但可能希望将声明放在循环之外。否则,列表将在每次迭代后(有效地)被清除。
用户按下第一个键,检测棋盘。板被写入 object_points
和 image_points
。然后用户按下键来校准相机。第一个键的处理结束,object_points
和 image_points
松散范围(并被清除),第二个键的处理开始,调用 calibrateCamera
一个空的 object_points
数组并失败。
在调用 calibrateCamera
之前,您还应该检查 object_points
是否不为空。
关于c++ - OpenCV calibrateCamera 断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23062035/
我想知道使用cvCalibrateCamera2来查找两个相机之间的旋转和平移的可能性有多大。 以您刚刚完成棋盘校准的场景为例,其中棋盘对于两个图像平面都是可见的。如果我然后将一个相机中的这些点作为
我正在校准我的相机,以消除图像失真。为了实现这个目标,我正在使用 OpenCV 库的校准相机功能。所以我用棋盘在真实引用系统中取点来提取点数。然后我用mm将这些点转换成真实的引用系。所以最后我得到两个
几天来,我一直在用棋盘示例进行相机校准。一切都很好(找到并显示角,然后馈送到数组)直到我调用最终函数 calibrateCamera。比我得到断言错误: OpenCV 错误:calibrateCame
我正在使用圆网格校准相机。相机位于 table 上方的固定位置,因此我使用单张图像进行校准。 (我将使用的所有对象都是平的,并且与我的校准图像在同一张 table 上。)我将圆心的真实位置放入 obj
我正在使用 calibrateCamera 执行相机校准。部分输出是一组 Rodrigues 旋转矢量和 3-D 平移矢量。 我对相机的世界位置感兴趣。如果我直接绘制翻译点,结果看起来不正确。我觉得我
我正在尝试为三角测量过程获取一个3x4 相机矩阵,但是calibrateCamera()仅返回 3x3 和 4x1 矩阵。 如何从这些矩阵中得到 3x4? 提前致谢! 最佳答案 calibrateCa
一段时间以来,我一直在尝试使用 Opencv calibrateCamera() 函数来校准我的相机。我遵循了 opencv 示例程序中描述的相同过程。我试图首先加载 10 9 x 6 棋盘图像。然后
我正在尝试让calibrateCamera在我的Node.js后端上工作。该库运行正常,但是如果输入错误,我会遇到OpenCV函数无法给出任何错误消息的麻烦。我有点在黑暗中飞翔。 但这不是重点。我已经
我想将 findChessboardCorners 与 calibrateCamera 一起使用,但在使用 calibrateCamera 时遇到错误。输出不是很有帮助。 OpenCV Error:
我正在使用 OpenCV 的 calibrateCamera 并试图了解它如何计算重投影误差以及该误差代表什么。它似乎是投影点和测量图像点之间的(欧几里得)距离的 RMS——对吗?然而,最终的重投影误
当我尝试使用 cv2.calibrateCamera 校准相机时出现以下错误: rms, camera_matrix, dist_coefs, rvecs, tvecs = cv2.calibrate
我试图从函数 cv::calibrateCamera() 中获取 cameraMatrix,实际上我不确定我做的是否正确,我最初的想法是: 获取来自同一相机的两张输入图像。 提取image_1和ima
我有一个 python 脚本,它使用 calibratecamera2 方法从棋盘的几个 View 校准相机。成功校准后,我追踪所有原始点并绘制一些图并再次计算重新投影误差。令我惊讶的是,opencv
我正在尝试使用 cv::calibrateCamera 来校准相机+投影仪系统。虽然它有时似乎有效,但在许多情况下,估计的解决方案似乎与正确的解决方案相去甚远。 这是一个显示问题的代码示例(包括所有数
我正在使用 VisualStudio 2010 和 OpenCV 3.0。我想校准相机,我遇到的问题与 this 中描述的基本相同去年发的帖子,一直没回复。我正在调用 calibrateCamera,
我有一个立体相机装置。我已经捕获了一个 chessboardPattern 序列(相同的序列,每次曝光两张照片)。我使用 cv2.calibrateCamera 对各个相机执行了单个相机校准。 我的问
背景: 我目前正在使用 OpenCV 进行立体视觉项目。我正在尝试从一组两个校正图像创建视差图,但我没有得到我期望的结果。查看校正后的图像时,图像之间存在明显的垂直偏移,校正后不应存在。我目前正在寻找
我正在尝试使用OpenCV calibrateCamera函数来校准我的MSFT LifeCam 3000 HD网络摄像头。为此,我了解需要知道fx和fy(x和y轴的焦距)。但是,我很难找到这些信息。
大家好,我一直在使用 Python 和 OpenCV 深入研究计算机视觉,并尝试校准我购买的两台相机,以便进行一些 3D 立体重建,但我遇到了一些问题。 我主要关注的是这个tutorial为了分别校准
calibrateCamera 的定义是:CV_EXPORTS_W double calibrateCamera( InputArrayOfArrays objectPoints,InputArray
我是一名优秀的程序员,十分优秀!