Doubts in camera calibration - matlab

I am working on a project based on machine vision . Wide angle lens with high resolution pinhole camera is being used.
Working distance : Distance between Camera and object .
The resolution will be nearly 10MP. The image size may be 3656 pixel width and 2740 pixel height.
The project requirements are as mentioned below
My working distance must be nearly 5metres.
The camera needs to be tilted at an angle of 13 degree.
To avoid lens distortion in camera I do camera calibration using OpenCV.
Below mentioned are my doubts pertaining to this camera calibration
Since the working distance is 5 meters, should the camera calibration too be done with the same distance?
Since the camera is tilted by an angle 13deg in the application ,is it necessary to do the calibration too with the camera tilted at respective angle?

My answer is "maybe" to the first question, and "no" to the second.
While it is true that it is not strictly necessary to calibrate with the target at the same or nearby distance as the subject, in practice it is possible only if you have enough depth of field (in particular, if you are focused at infinity), and use a fixed iris.
The reason is the Second Rule of Camera Calibration: "Thou shalt not touch the lens during or after calibration". In particular, you may not refocus nor change the f-stop, because both focusing and iris affect the nonlinear lens distortion and (albeit less so, depending on the lens) the field of view. Of course, you are completely free to change the exposure time, as it does not affect the lens geometry at all.
See also, for general comment, this other answer of mine.

The answer is no to both questions. Camera calibration essentially finds the relationship between the focal length and the pixel plane when assuming the pinhole camera model; and optionally (as you will require due to your wide angle lens), radial distortion. These relationships are independent of the position of the camera in the world.
By the way, I see you tagged this as matlab: I can recommend the Camera Calibration Toolbox for MATLAB as a nice easy way of calibrating cameras. It guides you through process nicely.

That angle of the camera is not a problem, but you do want to calibrate your camera with the calibration target at roughly the working distance from it. In theory, the distance should not matter. In reality, though, you will have greater errors if you calibrate at 1 meter, and then try to measure things 5 meters away.
Also, please check out the CameraCalibrator App that is a part of the Computer Vision System Toolbox for MATLAB.

Related

Optical lense distance from an object

I am using a Raspberry PI camera and the problem in hand is how to find the best position for it in order to fully see an object.
The object looks like this:
Question is how to find the perfect position given that the camera is placed in the centre of the above image. Perfectly the camera will be able to catch the object only, as the idea is to get the camera as close as possible.
Take a picture with you camera, save it as a JPG, then open it in a viewer that allows you to inspect the EXIF header. If you are lucky you should see the focal length (in mm) and the sensor size. If the latter is missing, you can probably work it out from the sensor's spec sheet (see here to start). From the two quantities you can work out the angle of the field of view (HorizFOV = atan(0.5 * sensor_width / focal_length), VertFOV = atan(0.5 * sensor_height / focal_length). From these angles you can derive an approximate distance from your subject that will keep it fully in view.
Note that these are only approximations. Nonlinear lens distortion will produce a slightly larger effective FOV, especially near the corners.

Restoring the image of a face's plane

I am using an API to analyze faces in Matlab, where I get for each picture a 3X3 rotation matrix of the face's orientation, telling which direction the head is pointing.
I am trying to normalize the image according to that matrix, so that it will be distorted to get the image of the face's plane. This is something like 'undoing' the projection of the face to the camera plane. For example, if the head is directed a little to the left, it will stretch the left side to (more or less) preserve the face's original proportions.
Tried using 'affine2d' and 'projective2d' with 'imwarp', but it didn't achieve that goal
Achieving your goal with simple tools like affine transformations seems impossible to me since a face is hardly a flat surface. An extreme example: Imagine the camera recording a profile view of someone's head. How are you going to reconstruct the missing half of the face?
There have been successful attempts to change the orientation of faces in images and real-time video, but the methods used are quite complex:
[We] propose a gaze correction method that needs just a
single webcam. We apply recent shape deformation techniques
to generate a 3D face model that matches the user’s face. We
then render a gaze-corrected version of this face model and
seamlessly insert it into the original image.
(Giger et al., https://graphics.ethz.ch/Downloads/Publications/Papers/2014/Gig14a/Gig14a.pdf)

Face detection MATLAB - slanted and up side down

I am working on a MATLAB project which enables the user to do face detection and blur them out.
Built-in functions used:
vision.CascadeObjectDetector
The problem with this function: It only detects frontal faces.
The methods I tried: Use imrotate function in a while loop to rotate the image while the degree is less then 360. So I thought that it would work. I increment the rotation by 23 everytime.
Cons: It doesn't work, it changes the spatial resolution of the image.
I have done some experiments in the past, and I have learned that the vision.CascadeObjectDetector using the default frontal face model can tolerate about 15 degrees of in-plane rotation. So I would advise rotating the image by 15 or even 10 degrees at a time, rather than 23.
The problem with training your own detector in this case is the fact that the underlying features (Haar, LBP, and HOG) are not invariant to in-plane rotation. You would have to train multiple detectors, one for each orientation, every 15 degrees or so.
Also, are you detecting faces in still images or in video? If you are looking at a video, then you may want to try tracking the faces. This way, even if you miss a face because somebody's head is tilted, you'll have a chance to detect it later. And once you detect a face, you can track it even if it tilts. Take a look at this example.

iPhone - What does the gyroscope measures? Can I get an absolute degree measurement in all axis?

I am relatively new to iPhone development and I am playing with the gyroscope, using Core Motion. After a few tests, this is my question.
What information is exactly the gyroscope measuring? absolute angles? I mean, suppose I hold my phone in portrait, at exactly 90 degrees and start sampling. These may be not the correct values, but suppose that at this position, the gyroscope gives me 0, 0 and 0 degrees for yaw, pitch and roll.
Now I throw my iphone in the air and as it goes up it rolls at random a high number of full turns in all axis and returns to my hand at the same position as before. Will the gyroscope read 0,0,0 (meaning that it has the same position as before = absolute angle) or not?
If not, there's a way to measure absolute degrees in all axis? As absolute degrees I mean assuming 0,0,0 as the position it was when the sampling started.
thanks
The gyroscope measures many things for you, and yes, one of these is "absolute angles". Take a look at the docs on CMDeviceMotion. It can give you a rotation rate, which is how fast the device is spinning, and it can give you a CMAttitude. The CMAttitude is what you're calling "absolute angles". It is technically defined as:
the orientation of a body relative to
a given frame of reference
The really nice thing is that normal gyroscopes, as noted in the other answer, are prone to drift. The Core Motion framework does a lot of processing behind the scened for you in an effort to compensate for the drift before the measurements are reported. Practically, I've found that the framework does a remarkable (though not perfect) job at this task. Unless you need long term precision to a magnetic pole or something, the attitude reported by the framework can be considered as a perfect relative attitude measurement, for all intents and purposes.
The iPhone uses accelerometers for its internal angle measurements, which means they are relative to the Earth's gravity. That's about as absolute as you're going to get, unless you need this program to work in space, too.

Calculating corresponding pixels

I have a computer vision set up with two cameras. One of this cameras is a time of flight camera. It gives me the depth of the scene at every pixel. The other camera is standard camera giving me a colour image of the scene.
We would like to use the depth information to remove some areas from the colour image. We plan on object, person and hand tracking in the colour image and want to remove far away background pixel with the help of the time of flight camera. It is not sure yet if the cameras can be aligned in a parallel set up.
We could use OpenCv or Matlab for the calculations.
I read a lot about rectification, Epipolargeometry etc but I still have problems to see the steps I have to take to calculate the correspondence for every pixel.
What approach would you use, which functions can be used. In which steps would you divide the problem? Is there a tutorial or sample code available somewhere?
Update We plan on doing an automatic calibration using known markers placed in the scene
If you want robust correspondences, you should consider SIFT. There are several implementations in MATLAB - I use the Vedaldi-Fulkerson VL Feat library.
If you really need fast performance (and I think you don't), you should think about using OpenCV's SURF detector.
If you have any other questions, do ask. This other answer of mine might be useful.
PS: By correspondences, I'm assuming you want to find the coordinates of a projection of the same 3D point on both your images - i.e. the coordinates (i,j) of a pixel u_A in Image A and u_B in Image B which is a projection of the same point in 3D.