Setting up the Camera

You can set up the camera using CamSet.py, which you can copy from here. (You will need to install the Python image modules before you can run CamSet.py, but you do not need to install OpenCV. See the next section. You will also need to have the camera server running on the Zero. See the previous section.) CamSet.py requests an image from the camera server whenever you click the left mouse button. (The CamSet.py window must have focus when you do that.) When the image is received, it is displayed in the window.

I took these pictures with a Raspberry Pi Zero with an attached ZeroCam taped to a door frame looking down at a chess board 1.55 m below. This section shows the effect of the camera settings at the beginning of the camera server PiCam.py. There is no specific documentation for the ZeroCam, but it supports the standard Python Pi Camera interface. Here is a camera image with no geometry settings applied at the default resolution of 720 x 480:


The board is reasonably well centred in the field of view. The next step is to make the image square and increase the resolution slightly. Here is the camera image after camera.resolution = (540, 540)


That is good, but there is lots of empty space. The ZeroCam is likely to have 1920 x 1080 as one of its native resolutions, which should make it easy to generate a 540 x 540 image. My early tests suggested that this resolution was indeed a good compromise between image quality and speed. The next step is to zoom in on the chess board. The zoom setting is is determined by (x, y, w, h), which is a tuple of floating point values ranging from 0.0 to 1.0, indicating the proportion of the image to include in the output. The default value is (0.0, 0.0, 1.0, 1.0), which indicates that everything should be included. Here is the camera image after camera.zoom = (0.25, 0.25, 0.5, 0.5)


That is also good. The final step is to rotate the image. Here is the camera image after camera.rotation = 270 


That is fine. The board position could do with some fine adjustment, but the position is good enough to enable the board to be recognised and the pieces to be detected. I also found that I needed to increase the exposure compensation by one stop to make the dark green squares brighter. Ideally, the board should be lit from above to minimise shadows, but I did not need any special lighting. I got excellent results with a standard 60W equivalent LED high colour temperature light bulb in the hallway and also in the other room adjacent to the board. Natural light from a window on one side was less effective.

Comments