Collision Avoidance using OpenCV on iPad

asked 2012-07-19 00:22:28 -0600

ameyazing gravatar image

I'm working on a project where I need to implement collision avoidance using OpenCV. This is to be done on iOS (iOS 5 and above will do).

Project Objective: The idea is to mount an iPad on the car's dashboard and launch the application. The application should grab frames from the camera and process these to detect if the car is going to collide with any obstacle.

I'm a novice to any sort of image processing, hence I'm getting stuck at conceptual levels in this project.

What I've done so far:

  • Had a look at OpenCV and read about it on the net. Collision avoidance is implemented using Lukas-Kanade Pyramid method. Is this right?
  • Using this project as a starting point: http://aptogo.co.uk/2011/09/opencv-framework-for-ios/ It successfully runs on my iPad and capture functionality works as well, which means camera capture is well-integrated. I changed the processFrame implementation to try Optical Flow instead of Canny edge detection. Here is the function (incomplete yet).

        -(void)processFrame {
        int currSliderVal = self.lowSlider.value;
        if(_prevSliderVal == currSliderVal) return;
        cv::Mat grayFramePrev, grayFrameLast, prevCorners, lastCorners, status, err;
    
    
    // Convert captured frame to grayscale for _prevFrame
    cv::cvtColor(_prevFrame, grayFramePrev, cv::COLOR_RGB2GRAY);
    cv::goodFeaturesToTrack(grayFramePrev, prevCorners, 500, 0.01, 10);
    // Convert captured frame to grayscale for _lastFrame
    cv::cvtColor(_lastFrame, grayFrameLast, cv::COLOR_RGB2GRAY);
    cv::goodFeaturesToTrack(grayFrameLast, lastCorners, 500, 0.01, 10);
    
    cv::calcOpticalFlowPyrLK(_prevFrame, _lastFrame, prevCorners, lastCorners, status, err);
    self.imageView.image = [UIImage imageWithCVMat:lastCorners];
    _prevSliderVal = self.lowSlider.value;
    
    }
  • Read about Optical Flow and how it is used (conceptually) to detect impending collision. Summary: If an object is growing in size, but moving towards any edge of the frame, then it is not a collision path. If an object is growing in size, but not moving towards any edge, then it is on collision path. Is this right?
  • This project (http://se.cs.ait.ac.th/cvwiki/opencv:tutorial:optical_flow) appears to be doing exactly what I want to achieve. But I did not understand how it is doing so by reading the code. I cannot run it as I don't have a linux box. I read the explanation on this web-page, it seems to arrive at an homograph matrix. How is this result used in collision avoidance?

In addition to the above four points mentioned, I have read a lot more about this topic but still can't put all the pieces together.

Here are my questions (please remember I'm a novice at this)

  1. HOW is optical flow used to detect impending collision? By this I mean, supposing I'm able to get correct result from the function cv::calcOpticalFlowPyrLK(), how do I take it forward from there to detect impending collision with any object on the frame? Is it possible to gauge distance from the object we are most likely to collide with?

  2. Is there a sample working project which implements this or any similar functionality that I can have a look at. I had ...

(more)
edit retag flag offensive close merge delete

Comments

1

This paper describes one algorithm that might be useful: Animal-Inspired Agile Flight Using Optical Flow Sensing Good luck, this sounds like a fun project.

blue ( 2012-07-19 08:58:29 -0600 )edit

My opinion is that Optical Flow won't be enough for robust solution... Here is an article where authors have built a complete detection/classification pipeline to avoid collisions. And they did it for cars only, not for arbitrary objects!

Kirill Kornyakov ( 2012-09-30 03:31:19 -0600 )edit