Calibration With Python And Opencv
Solution 1:
The program you gave only display something if the corners have been found.
First, check that the image has successfully been loaded, by adding cv2.imshow('img',img)
just after img = cv2.imread(fname)
.
Second, it could be that the corners are not detected in the image you are using (which sometimes happen). Try the same program with simple images, where the chessboard is clearly visible in the center of the image.
Solution 2:
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "opencv2/contrib/contrib.hpp"
#include <stdio.h>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
//int numBoards = atoi(argv[1]);
//int board_w = atoi(argv[2]);
//int board_h = atoi(argv[3]);
int numBoards =50; // number of different poses
int board_w =122; // number of horizontal corners
int board_h =154; // number of vertical corners
Size board_sz = Size(board_w, board_h);
int board_n = board_w*board_h;
vector<vector<Point3f> > object_points;
vector<vector<Point2f> > image_points;
vector<Point2f> corners;
vector<Point3f> obj;
for (int j=0; j<board_n; j++)
{
obj.push_back(Point3f(j/board_w, j%board_w, 0.0f));
}
Mat img, gray;
VideoCapture cap = VideoCapture(0); //change to laptop on built web cam
int success = 0;
int k = 0;
bool found = false;
while (success < numBoards)
{
cap >> img;
cvtColor(img, gray, CV_BGR2GRAY);
found = findChessboardCorners(gray, board_sz, corners, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS);
if (found)
{
cornerSubPix(gray, corners, Size(11, 11), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1));
drawChessboardCorners(gray, board_sz, corners, found);
}
imshow("image", img);
imshow("corners", gray);
k = waitKey(1);
if (found)
{
k = waitKey(0);
}
if (k == 27)
{
break;
}
if (k == ' ' && found !=0)
{
image_points.push_back(corners);
object_points.push_back(obj);
printf ("Corners stored\n");
success++;
if (success >= numBoards)
{
break;
}
}
}
destroyAllWindows();
printf("Starting calibration\n");
Mat intrinsic = Mat(3, 3, CV_32FC1);
Mat distcoeffs;
vector<Mat> rvecs, tvecs;
intrinsic.at<float>(0, 0) = 1;
intrinsic.at<float>(1, 1) = 1;
calibrateCamera(object_points, image_points, img.size(), intrinsic, distcoeffs, rvecs, tvecs);
FileStorage fs1("/Users/venushka/Desktop/2015/mycalib.yml", FileStorage::WRITE);
fs1 << "CM1" << intrinsic;
fs1 << "D1" << distcoeffs;
printf("calibration done\n");
Mat imgU;
while(1)
{
cap >> img;
undistort(img, imgU, intrinsic, distcoeffs);
imshow("image", img);
imshow("undistort", imgU);
k = waitKey(5);
if (k == 27)
{
break;
}
}
cap.release();
return(0);
}
Try This code
Solution 3:
maybe the problem is because of that the line images = glob.glob('*.jpg') can't find the images. put it manually and check. For example: img = cv2.imread('left12.jpg')
Solution 4:
Maybe the problem is the code line
cv2.waitKey(500)
So even if you find the corners you won't realy see something, because this line only waits for 500 milliseconds until the window gets closed by
cv2.destroyAllWindows()
So replace 500 with zero and the window will remain open until you focus on it an klick a key on your keyboard.
Solution 5:
as i seen in the chessboard there is (7,7) corners but you put (7,6) in program
change this>> (7,6)
to this >> (7,7)
Post a Comment for "Calibration With Python And Opencv"