Ask Your Question
0

Find center and radius of fisheye image

asked 2015-07-28 01:35:28 -0600

TAXfromDK gravatar image

Hi Guys,

I have a video from a fisheye camera with an image like this. Dont mind the cutout of the person. :)

image description

I would like to find the center and radius of the circular fisheye image mage. I have tried just fitting a circle to the image, but the edge is very warped and reflections tend to bleed from the sides of the image so centering is difficult.

I therefore need something better.

I was therefore wondering if there was any way to find the contrast in the image andperhaps accumulate it over several video frames, to thereby detect what pixels contain world information and what contain bleeding.

Kind regards

Jesper

edit retag flag offensive close merge delete

Comments

Do you have access to the camera? I think it is better to take sample image of a Graph to find the center more accurately!

Balaji R gravatar imageBalaji R ( 2015-07-28 02:03:16 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-07-28 03:16:05 -0600

updated 2015-07-28 03:18:02 -0600

Depending on how accurcate you need it to be, I could give you this code snippet.

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main()
{
    // Read the image
    Mat image = imread("/home/spu/Desktop/test.jpg");
    Mat grayscale;
    cvtColor(image, grayscale, COLOR_BGR2GRAY);

    // Threshold the image
    // Since the edge is always black, lets use this to our advantage
    Mat mask;
    threshold(grayscale, mask, 0, 255, CV_8UC1);

    // Find the largest contour in the mask
    // Then find the center of gravity of all the points
    // If this is accurate enough it will be very close near the center
    vector< vector<Point> > contours;
    findContours(mask, contours, RETR_EXTERNAL, CHAIN_APPROX_NONE);
    drawContours(mask, contours, -1, 255, 2);

    // Loop over contours and find the largest ones based on the area
    // This will ensure that small artefacts do not break this down
    vector<Point> largest_contour = contours[0];
    for(size_t i=0; i<contours.size(); i++){
        if(contourArea(contours[i]) > contourArea(largest_contour)){
            largest_contour = contours[i];
        }
    }

    // Now find the minimum enclosing circle
    Point2f center;
    float radius;
    minEnclosingCircle(largest_contour, center, radius);

    // Draw the centerpoint on the original image
    circle(image, center, 2, Scalar(0,0,255), -1);
    circle(image, center, 10, Scalar(0,255,0), 2);
    stringstream temp;
    temp << "the radius = " << radius << " /" << " the center = " << center;
    putText(image, temp.str(), Point(50,50), FONT_HERSHEY_COMPLEX, 1, Scalar(0,255,0));
    imshow("result", image); waitKey(0);

    return 0;
}

which will result in the following image

image description

But actually I am pretty convinced that if you would just take the following pseudo code, that the end result might even be better

Point center (image.cols/2, image.rows/2);
float radius = image.rows/2;

Because most of those cameras return you a square video with the fisheye result exactly in the middle.

edit flag offensive delete link more

Comments

1

Thank you very much!!! This is awesome :)

TAXfromDK gravatar imageTAXfromDK ( 2015-07-28 15:01:27 -0600 )edit
1

No problem, that was actually fun to have a new toy example to play around with.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-07-29 02:33:12 -0600 )edit

Hi, I just found this, this is very useful for me as I also need to find the center/radius of a fisheye image, could you indicate how to run this script, and if its possible to output a text file instead of the modified picture ?

I'd really appreciate it, thank you

Cy

Cy gravatar imageCy ( 2018-06-06 22:53:43 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-07-28 01:35:28 -0600

Seen: 2,198 times

Last updated: Jul 28 '15