Assignment 1 - Use OpenCV for camera calibration

Similar documents
Camera Model and Calibration

Lecture 5.3 Camera calibration. Thomas Opsahl

Camera Model and Calibration. Lecture-12

Camera Calibration. Schedule. Jesus J Caban. Note: You have until next Monday to let me know. ! Today:! Camera calibration

Multimedia Retrieval Exercise Course 2 Basic of Image Processing by OpenCV

Check the Desktop development with C++ in the install options. You may want to take 15 minutes to try the Hello World C++ tutorial:

Computer Vision. Coordinates. Prof. Flávio Cardeal DECOM / CEFET- MG.

LS-ACTS 1.0 USER MANUAL

3D Geometry and Camera Calibration

Computer Vision, Laboratory session 1

Computer Vision: Lecture 3

Camera Models and Image Formation. Srikumar Ramalingam School of Computing University of Utah

Introduction to Homogeneous coordinates

Agenda. Rotations. Camera models. Camera calibration. Homographies

Image Transformations & Camera Calibration. Mašinska vizija, 2018.

Camera Models and Image Formation. Srikumar Ramalingam School of Computing University of Utah

CS6670: Computer Vision

stanford hci group / cs377s Lecture 8: OpenCV Dan Maynes-Aminzade Designing Applications that See

Robot Vision: Camera calibration

Computer Vision, Laboratory session 1

MERGING POINT CLOUDS FROM MULTIPLE KINECTS. Nishant Rai 13th July, 2016 CARIS Lab University of British Columbia

Perspective Projection [2 pts]

Rigid Body Motion and Image Formation. Jana Kosecka, CS 482

EECS 4330/7330 Introduction to Mechatronics and Robotic Vision, Fall Lab 1. Camera Calibration

Projector Calibration for Pattern Projection Systems

Vision Review: Image Formation. Course web page:

Image Processing (1) Basic Concepts and Introduction of OpenCV

ECE 661 HW 1. Chad Aeschliman

Pattern Feature Detection for Camera Calibration Using Circular Sample

Pin Hole Cameras & Warp Functions

IMPLEMENTATION OF COMPUTER VISION TECHNIQUES USING OPENCV

Homework #1. Displays, Image Processing, Affine Transformations, Hierarchical Modeling

Lecture 3: Camera Calibration, DLT, SVD

OpenCV. Rishabh Maheshwari Electronics Club IIT Kanpur

3D Sensing and Reconstruction Readings: Ch 12: , Ch 13: ,

NAME VCamera camera model representation

Geometric camera models and calibration

CIS 580, Machine Perception, Spring 2016 Homework 2 Due: :59AM

LUMS Mine Detector Project

Computer Vision Projective Geometry and Calibration. Pinhole cameras

Outline. ETN-FPI Training School on Plenoptic Sensing

Colorado School of Mines. Computer Vision. Professor William Hoff Dept of Electrical Engineering &Computer Science.

Computer Vision I Name : CSE 252A, Fall 2012 Student ID : David Kriegman Assignment #1. (Due date: 10/23/2012) x P. = z

Camera model and multiple view geometry

REDUCING THE VARIANCE OF INTRINSIC CAMERA CALIBRATION RESULTS IN THE ROS CAMERA_CALIBRATION PACKAGE GEOFFREY NELSON CHIOU, B.S.

Homework #1. Displays, Image Processing, Affine Transformations, Hierarchical Modeling

EN1610 Image Understanding Lab # 3: Edges

Agenda. Rotations. Camera calibration. Homography. Ransac

CS4670: Computer Vision

Chapter 6. Introduction to OpenCV

Introduction to 3D Machine Vision

Pin Hole Cameras & Warp Functions

Hand-Eye Calibration from Image Derivatives

Flexible Calibration of a Portable Structured Light System through Surface Plane

VSRS Software Manual. VSRS 4.0 (SVN tag: VSRS_4)

Computer Vision cmput 428/615

Cameras and Radiometry. Last lecture in a nutshell. Conversion Euclidean -> Homogenous -> Euclidean. Affine Camera Model. Simplified Camera Models

Massachusetts Institute of Technology Department of Computer Science and Electrical Engineering 6.801/6.866 Machine Vision QUIZ II

Colorado School of Mines. Computer Vision. Professor William Hoff Dept of Electrical Engineering &Computer Science.

PAPARA(ZZ)I User Manual

CS 6320 Computer Vision Homework 2 (Due Date February 15 th )

Camera model and calibration

Computer Vision. Geometric Camera Calibration. Samer M Abdallah, PhD

JRC 3D Reconstructor CAMERA CALIBRATION & ORIENTATION

CSE 252B: Computer Vision II

Image Formation. Antonino Furnari. Image Processing Lab Dipartimento di Matematica e Informatica Università degli Studi di Catania

Multimedia Retrieval Exercise Course 2 Basic Knowledge about Images in OpenCV

A COMPREHENSIVE SIMULATION SOFTWARE FOR TEACHING CAMERA CALIBRATION

Computer Vision CSCI-GA Assignment 1.

OpenCV. Basics. Department of Electrical Engineering and Computer Science

High Altitude Balloon Localization from Photographs

Homogeneous Coordinates. Lecture18: Camera Models. Representation of Line and Point in 2D. Cross Product. Overall scaling is NOT important.

CV: 3D to 2D mathematics. Perspective transformation; camera calibration; stereo computation; and more

CSCI 512 / EENG 512 Computer Vision Spring Lab 6. February 17, 2016

ECE661 Computer Vision : HW2

CS201 Computer Vision Camera Geometry

Camera Calibration. COS 429 Princeton University

ECE Digital Image Processing and Introduction to Computer Vision. Outline

Homework #1. Displays, Alpha Compositing, Image Processing, Affine Transformations, Hierarchical Modeling

Chapter 1. Linear Equations and Straight Lines. 2 of 71. Copyright 2014, 2010, 2007 Pearson Education, Inc.

Introduction to OpenCV

Computer Vision, Assignment 1 Elements of Projective Geometry

Camera Projection Models We will introduce different camera projection models that relate the location of an image point to the coordinates of the

Assignment 2 : Projection and Homography

Head Mounted Display Optics I!

Module 6: Pinhole camera model Lecture 32: Coordinate system conversion, Changing the image/world coordinate system

CIS 580, Machine Perception, Spring 2015 Homework 1 Due: :59AM

x + 2 = 0 or Our limits of integration will apparently be a = 2 and b = 4.

Matrix Transformations The position of the corners of this triangle are described by the vectors: 0 1 ] 0 1 ] Transformation:

COMP30019 Graphics and Interaction Perspective Geometry

Graphics Pipeline 2D Geometric Transformations

Measurement and Precision Analysis of Exterior Orientation Element Based on Landmark Point Auxiliary Orientation

Exterior Orientation Parameters

The real voyage of discovery consists not in seeking new landscapes, but in having new eyes.

1. Introduction to the OpenCV library

KCS Motion. Video Motion Analysis Software

Homework 1: Getting Started with WebGL and Transformations EE267 Virtual Reality 2018

Automatic Feature Extraction of Pose-measuring System Based on Geometric Invariants

3D Polygon Rendering. Many applications use rendering of 3D polygons with direct illumination

1 Affine and Projective Coordinate Notation

Transcription:

ME/CS 132A_Winter 2015 Theory Assignment 1 - Use OpenCV for camera calibration For the distortion OpenCV takes into account the radial and tangential factors. For the radial factor one uses the following formula: So for an old pixel point at (x,y) coordinates in the input image, its position on the corrected output image will be (x_corrected y_corrected). The presence of the radial distortion manifests in form of the barrel or fish-eye effect. Tangential distortion occurs because the image taking lenses are not perfectly parallel to the imaging plane. It can be corrected via the formulas: So we have five distortion parameters which in OpenCV are presented as one row matrix with 5 columns: Now for the unit conversion we use the following formula: Here the presence of w is explained by the use of homogeneous coordinate system (and w=z). The unknown parameters are f_x and f_y (camera focal lengths) and (c_x, c_y) which are the optical centers expressed in pixels coordinates. If for both axes a common focal length is used with a given aspect ratio a (usually 1), then f_y=f_x*a and in the upper formula we will have a single focal length f, which you learned in class. The matrix containing these four parameters is referred to as the camera matrix. While the distortion coefficients are the same regardless of the camera resolutions used, these should be scaled along with the current resolution from the calibrated resolution. The process of determining these two matrices is the calibration. Calculation of these parameters is done through basic geometrical equations. The equations used depend on the chosen calibrating objects. Currently OpenCV supports three types of objects for calibration:

Classical black-white chessboard Symmetrical circle pattern Asymmetrical circle pattern Basically, you need to take snapshots of these patterns with your camera and let OpenCV find them. Each found pattern results in a new equation. To solve the equation you need at least a predetermined number of pattern snapshots to form a well-posed equation system. This number is higher for the chessboard pattern and less for the circle ones. For example, in theory the chessboard pattern requires at least two snapshots. However, in practice we have a good amount of noise present in our input images, so for good results you will probably need at least 20 good snapshots of the input pattern in different positions. Goal: Learn to use OpenCV to: (1)Open("load") an image and display that image; (2)Take input from Camera, Video or Image file list; (3)calibrate image for camera calibration; Determine the distortion matrix Determine the camera matrix Save the results into XML/YAML file The codes for Part A, Part B, Part C and answers for Part D, the screenshot for Part A, the 25 bmp images you saved and used for Part C, and the XML file with parameter information should be archived with name "your name _ME132_HW1" and submitted via Wiki. A hard copy should also be turned in every Thursday before the lecture starts. Getting Started----Installing the OpenCV Library Step1: Click on the following link and download OpenCV-2.2.0-win32-vs2010.exe http:// sourceforge.net/projects/opencvlibrary/files/opencv-win/2.2/ When installing, by default, you can make you download path as "C:\OpenCV 2.2". Remember to select "Add OpenCV to the system PATH for all users". If it doesn't work, add to the system path manually by yourself. Finding the following path: "control panel->system->advanced system setting->system->environmental variables->path". Then add "opencv/bin" to the path. The bin file should be in your installation file of OpenCV.

Step2: Configure the setup In Visual Studio, it is necessary to create a project and to configure the setup so that the necessary libraries are linked, and the preprocessor will search your OpenCV include directories for header files. Once you have done this, you create a new C++ file and start your first program. To be concrete, you need to create a Win32 Console Application in VS2010 environment. In "Configuration Properties-VC++ Directories-Include Directories", add the following 3 directories: C:\OpenCV2.2\include; C:\OpenCV2.2\include\OpenCV; C: \OpenCV2.2\include\OpenCV2. In "Configuration Properties-VC++ Directories-Library Directories", add C: \OpenCV2.2\lib. In "Linker-Input-Additional Dependencies", add opencv_highgui220d.lib; opencv_core220d.lib; opencv_imgproc220d.lib; Part A- Open(load) an image and display that image (10%) This part is relatively easy. The necessary header file you need to include is "highgui.h". Also here are some useful functions in OpenCV Library: cvloadimage(img_file_name,1); cvnamedwindow(img_file_name,cv_window_autosize); cvshowimage(img_file_name,img); cvwaitkey(0); cvreleaseimage(&img); cvdestroywindow(img_file_name); Requirements: In this first program, you are required to load an image into memory and display it on the screen. Remember to get a screenshot of the window displaying that image. The raw image is provided with the file name "First_Image". Part B - Take input from Camera, Video or Image file list (20%) Vision can mean many things in the world of computers. In some cases we are analyzing still frames loaded from elsewhere. In other cases we are analyzing video that is being read from disks. In still other cases, we hope to work with real-time data streaming in from some kind of camera device. In Part A, you know how to load a static image from your computer, in this section, you need to get real-time video stream from a camera, whether a USB webcam from outside your computer or the camera set on your own computer. Also, you need to grasp how to save image files captured by your camera anytime you press a key on your keyboard. In OpenCV, more specifically, the HighGui portion of the OpenCV library provides us with an easy way to handle this situation. Calling cvcreatecameracapture() is a routine way to do this. However, if we hope to set multiple cameras in our program and conveniently select any camera we want, it will be much more helpful for Computer Vision problems later. In OpenCV 2.2, we turn to DirectShow to realize our hope to select from multiple cameras.

Download the zip file of CameraDS using the following link. After decompressing the file, put DirectShow folder into your project folder, like \Project\First_Project, add the five files Camera.cpp, CameraDS.h, stdafx.cpp, stdafx.h, targetver.h into \Project\First_Project \First_Project. Then add the cpp file CameraDS.cpp to your project which means your own cpp file and this cpp file should be in the same folder. Finally, remember to include necessary directories. In "Configuration Properties-VC++ Directories-Include Directories", add DirectShow \include. https://drive.google.com/folderview? id=0b81nquinfbtytvjubl9ld1y4ams&usp=drive_web&ddrp=1# Requirements: In the second program, you need to get real-time video input from the camera on your own computer. While pressing "m" or "M" on your keyboard, the image in that video is captured and saved to your computer. For convenience in Part C, please print out the chessboard picture "Chessboard_10_7" and hold it when you are using your camera to get video input(so we can see that is you). Then save 25 different images with bmp format and name those images as "IMG_SAVED000", "IMG_SAVED001"..."IMG_SAVED024". A possible version of the whole codes are provided as follows but you still need to program and modify a little bit by yourself. #include"stdafx.h" #include<cv.h> #include<highgui.h> #include<stdio.h> #include"camerads.h" #define CAP_WIDTH 320 #define CAP_HEIGHT 240 int main() IplImage* capimg; CvCapture* capture; int loop =1; int file_idx=0; int key; int DeviceCamCount; char filename[256]; char fileidx[10]; int CamCount=0; int CamIndex[10]; CCameraDS *pcamds =NULL; pcamds= new CCameraDS(); DeviceCamCount=pCamDS->CameraCount(); if(devicecamcount == 0) printf("no Camera detected...\n"); return(-1); for( int i=0,j=0; i<devicecamcount;i++) char szcamname[1024];

int retval=pcamds->cameraname(i,szcamname,sizeof(szcamname)); if(retval>0) // select the camera, you probably need to modify codes here. printf("camera #%d's name is '%s'.\n",i,szcamname); if(strcmp(szcamname,"usb..")) CamIndex[j++]=i; CamCount++; else printf("cannot get camera #%d's name.\n",i); if(pcamds->opencamera(camindex[0],false,cap_width,cap_height)==false) printf("camera do not support w=%d:h=%d\n",cap_width,cap_height); return(-1); cvnamedwindow("camera0",1); while(loop) capimg = pcamds ->QueryFrame(); cvshowimage("camera0",capimg); key=cvwaitkey(5); if(key==27) // 27 is the ASCII code of "ESC", when you press ESC, you exit the program loop=0; else if(fill YOUR CODES) // press "m" or "M" to save the image(bmp file) FILL YOUR CODES if(pcamds) pcamds->closecamera(); delete pcamds; cvdestroywindow("camera0"); return(0); Part C - Use OpenCV for Camera Calibration (50%) In general, any object can be used as a calibration object. OpenCV opts for a chessboard which ensures that there is no bias toward one side or the other in measurement. Also, the resulting grid corners lend themselves naturally to the subpixel localization functions. Given an image of a chessboard(or a person holding a chessboard picture), use OpenCV function cvfindchessboardcorners(img,boardsize,imagecorners) to locate the corners of the chessboard. The first argument "image" is an 8-bit grayscale(single-channel) image. It is

actually the input image with a chessboard on it. The second argument "boardsize" indicates how many corners are in each row and column. It is counting the interior corners. Its type is Cvsize(M,N), Here is the function definition: int cvfindchessboardcorners( const void* image, Cvsize boardsize,cvpoint2d32f* imagecorners); The corners returned by cvfindchessboad Corners() are only approximate, and you should use OpenCV function cornersubpix() to get exact values of locations of corners. Neglecting to call this refinement after you first locate the corners will probably cause substantial errors in calibration. You will probably write exactly the following codes when calling this function. cornersubpix(image, imagecorners, cvsize(11,11), cvsize(-1,-1), cvtermcriteria(cv::termcriteria::max_iter + cv::termcriteria::eps,30, 0.1)); Next, OpenCV function cvdrawchessboardcorners() will label the corners onto an image you provide. Here is the function definition: void cvdrawchessboardcorners( CvArr* image, CvSize boardsize, CvPoint2D32f* corners, int pattern_found); Finally, call calibratecamera() for camera calibration. This OpenCV function will take the chessboard images and output the camera intrinsic matrix and distortion coefficient vector. The following codes are what you need to write when calling this function. calibratecamera(objectpoints, // the 3D points imagepoints, // the image points imagesize, // image size cameramatrix,// camera intrinsic matrix distcoeffs, // distortion coefficient matrix rvecs, tvecs,// rotation and translation vector 0); After you have done with the following functions, you need to save your parameter information(camera intrinsic matrix and distortion coefficient vector) to a XMY file. Codes are as follows: FileStorage fs("test.yml", FileStorage::WRITE); fs << "intrinsic" << cameramatrix; fs << "distcoeff" << distcoeffs; Requirements: In the third and last program, use the 25 images in get in Part B which are "IMG_SAVED000"..."IMG_SAVED024" and run your codes you write to get calibrated images and XMY file which includes the parameter information. Just take the 25 images as input and see what happens when you successfully run you codes in Part C. Putting all above together, a possible version of the codes of the main part without the header files is as follows. The highlighted red part of the codes is where you need to write codes for above OpenCV functions or make some changes to make the whole program work. #define CAP_WIDTH 640 #define CAP_HEIGHT 480 std::vector<std::vector<cv::point3f>> objectpoints;

std::vector<std::vector<cv::point2f>> imagepoints; cv::mat cameramatrix; cv::mat distcoeffs; cv::mat map1,map2; int main() cv::mat img; cv::mat img2; IplImage* capimg; int DeviceCamCount = 0; CCameraDS *pcamds = NULL; int CamCount = 0; int CamIndex[10]; pcamds = new CCameraDS(); DeviceCamCount = pcamds->cameracount(); int i; int loop = 1; int key; int file_idx = 0; char filename[256]; char fileidx[10]; //Define the variable "boardsize" here; cv::size imagesize(cap_width, CAP_HEIGHT); std::vector<cv::point2f> imagecorners; std::vector<cv::point3f> objectcorners; for (int i=0; i<boardsize.height; i++) for (int j=0; j<boardsize.width; j++) objectcorners.push_back(cv::point3f(i, j, 0.0f)); while ( loop ) //Find the chessboard bmp images here; printf("img = %s\n", filename); img = imread( filename, 0 ); if ( img.empty()) loop = 0; else //Find the chessboard corners here; //Find exact values of locations of corners here; if (imagecorners.size() == boardsize.area()) imagepoints.push_back(imagecorners); objectpoints.push_back(objectcorners); img.copyto( img2 ); //Draw chessboard corners here; imshow( "image", img2 );

key = cvwaitkey(400); if ( key == 27 ) loop = 0; std::vector<cv::mat> rvecs, tvecs; //Use calibratecamera() for camera calibration here; //Save parameter information to XML file here; Part D - Understand better the camera parameters (20%) Based on what you get from Part C, please answer the following questions: a-what is the aspect ratio of the image? b-what is the horizontal and vertical resolution of your camera? c-what is the field of view of the camera? d-what does each element mean in your 1*5 distortion coefficient vector? What can you know about the radial distortion and tangential distortion of your camera?