0

I have a video sequence of which one frame is shown below as shown below. I was trying to use corner detection to find the edges of the rectangle on the sheet of paper.

Webcam Image

I am using the Shi-Tomasi corner detector for the same. However it detects a number of other things that I don't need from the background of the image. How can I narrow down my ROI to only the sheet of paper.

Second Question:
In the video sequence upon detecting The corners I need to play another video inside the rectangle. I was trying to do this using a single thread but it lead to a lot of lag and jerks. What can I possibly do to improve my processing speed. Do I need to use multiple threads for each video. One video is from the webcam while the other is from the hard-drive.

Sohaib
  • 4,058
  • 7
  • 35
  • 66
  • I am not sure if you have gone through these link are not but the may help. http://stackoverflow.com/questions/10533233/opencv-c-obj-c-advanced-square-detection http://stackoverflow.com/questions/8667818/opencv-c-obj-c-detecting-a-sheet-of-paper-square-detection/8863060#8863060 – user2727765 Oct 02 '13 at 16:25

1 Answers1

1

Here is what I did for one of previous projects.

  1. Find all contours in your picture and approximate each with 4 corner shape
  2. Find right rectangle with your own condition such as rectangle with area > 1000000
  3. (optional) you will notice that your rectangle is not real rectangle because of 3D world. You might want to do perspective transformation to get correct rectangle
  4. Paint green or whatever texture on the found rectangle since you already have 4 corners from above

As for jerky playing, you might want to use not only multithreading with GPU but also encryption to improve speed.

Tae-Sung Shin
  • 18,949
  • 31
  • 125
  • 230
  • How do I approximate with a four corner shape. I am new to this library so it would be very nice if you could elaborate a bit. – Sohaib Oct 02 '13 at 15:12
  • Such as approxPolyDP. For more details, refer to http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#approxpolydp – Tae-Sung Shin Oct 02 '13 at 15:14
  • I did as much. I think I am asking a very basic question but how do I ascertain that a polygon approximated using approxPolyDP is a rectangle? – Sohaib Oct 02 '13 at 15:16
  • #3 is dealing with that. The rectangle you want to find is not really mathematical rectangle. When searching the correct shape, you have to manipulate your condition in #2. – Tae-Sung Shin Oct 02 '13 at 15:18
  • 1
    Please see this link. It tries to find out of rectangles. I can't get the function to work though as it has same identifier angle which I am not able to understand. http://opencv-code.com/tutorials/detecting-simple-shapes-in-an-image/ – Sohaib Oct 02 '13 at 16:15
  • Read the text in care. Given a contours, the program approximate a polygonal curve for that contours. This polygonal curve is the key for detecting the contour’s shape. In the snippet above, the shape is determined to be a rectangle if the polygonal curve meets the following conditions: It is convex. It has 4 vertices. All angles are ~90 degree. – Tae-Sung Shin Oct 02 '13 at 16:25
  • I did everything and I got the result I want except the perspective transform. I don't know why but it doesn't seem to do any change to the final result. Regarding the performance considerations I don't understand how encryption increases speed. – Sohaib Oct 02 '13 at 19:41