4

I have to do the following work:

1. Draw a chessboard with at least 9x6 squares.
2. Take a video using a still camera and place the chessboard on the scene to find a Homography.
3. Remove the calibration target from the scene and compute the background model.
4. Place a moving object in the scene on the same plane as the Chessboard. Just a few seconds are enough
5. Calculate a homography using the frame with the chessboard
6. For each frame with the object: a. Subtract the background and calculate the object's position in the image. B. Use a homography and calculate the object's position on the plane where the chessboard was
7. Draw on a graph as found and connect the dots

What means the point 6b and how to do it?

What I have is this:

enter image description here

Am I right? or isnt this way:?

UPDATE
I tried this code:


chessboard_frame = cv.imread('pen.png',0)          # queryImage
chessboard_template = cv.imread('boardTemplate.png',0) 

pattern_size = (10,10)
_, corners1 = cv.findChessboardCorners(chessboard_frame, pattern_size)
_, corners2 = cv.findChessboardCorners(chessboard_template, pattern_size)
H, _ = cv.findHomography(corners1, corners2)

but it throws the following error:

error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-czu11tvl\opencv\modules\calib3d\src\fundam.cpp:378: error: (-5:Bad argument) The input arrays should be 2D or 3D point sets in function 'cv::findHomography'

HelloWorldd
  • 172
  • 2
  • 14

1 Answers1

0

The assignment is a bit unclear. This is what I understand you need to do

  1. All frames below should be taken from a steady camera viewing a planar surface for some angle.
  2. Take one frame with the chessboard on a planar surface.
  3. Take one frame of the planar surface without chessboard (this is the background frame).
  4. Take a set of frames of a moving object on top of the plane (no chessboard).
  5. The result should be a XY plot of the place of the object relative to the given plane. The chessboard actually defines the (0,0) and scale of the plane.

you will also need a template image of the chessboard. I suggest a chessboard of pattern size (9,6) from here.

First, find the homography H from the camera to the template (assuming gray-level image):

pattern_size = (9,6)
_, corners1 = cv.findChessboardCorners(chessboard_frame, pattern_size)
_, corners2 = cv.findChessboardCorners(chessboard_template, pattern_size)
H, _ = cv.findHomography(corners1, corners2)

Use the background frame and subtract from each frame to get only the mask of the object:

object_mask =  np.abs(frame-bg_frame) < threshold

Take the mean of the mask to get a one pixel coordinate representing your object:

uv_coordinates = np.mean(np.argwhere(object_mask), axis=0)

Finally, transform the uv_coordinates to template_coordinates for you to later plot frame by frame:

uv1_coordinates = np.append(uv_coordinates,1).reshape(-1,1) # now size 3X1
template_xy1_coordinates = H@uv1_coordinates # matrix multiplication
template_coordinates = template_xy1_coordinates.flatten()[:2] # result shape (2,)
YoniChechik
  • 1,397
  • 16
  • 25
  • @HelloWorldd try pattern size (9,9) and please read the findchessboardcorners docs to see if the return from that code is actually valid. I belibe your error is there but cannot do anything without a full example and your origonal images. – YoniChechik Aug 11 '21 at 00:12
  • furthermore I advise you to use an assymetric board- please see my tutorial at: https://www.aiismath.com/pages/c_07_camera_calibration/multi_plane_calib_nb/ – YoniChechik Aug 11 '21 at 00:19
  • With 9,9 the error persists. ['boardTemplate.png'](https://imgur.com/mnSP91i) | ['pen.png'](https://imgur.com/K4vvZIY) | ['pen3.png'](https://imgur.com/jQr78FR) – HelloWorldd Aug 11 '21 at 00:20
  • using an image of the board with the pen on it is also a problem since this will hide the corners. Please read again my interpretation of the assignment. – YoniChechik Aug 11 '21 at 00:24
  • The fact is I dont understand the requirements properly, but i know that I have to moviment an object through the scene and show a chart with the points between the board and the object, or something like that – HelloWorldd Aug 11 '21 at 00:29
  • Please see updated answer on what I believe the assignment should be. – YoniChechik Aug 11 '21 at 13:10