Vision 2D: Lab: Sounkalo DEMBÉLÉ, Mayra Yucely BEB CAAL Université de Franche-Comté
Vision 2D: Lab: Sounkalo DEMBÉLÉ, Mayra Yucely BEB CAAL Université de Franche-Comté
Université de Franche-Comté
Contents
1 Introduction 2
2 Training 3
2.1 Experimental setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Analysis of imaging system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2.1 Reading of video stream from camera . . . . . . . . . . . . . . . . . . . . . . 4
2.2.2 Objective of 25 mm focal length . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2.3 Objective of 25 mm focal length with extension tube . . . . . . . . . . . . . 5
2.3 Reading, processing and analysis of single image . . . . . . . . . . . . . . . . . . . . 5
2.4 Reading, processing and analysis of video stream from le . . . . . . . . . . . . . . 7
3 Testing 8
1
Chapter 1
Introduction
The educational objective of the lab is initiation into computer vision through OpenCV with
Python by applying it to the metrology of colored targets. OpenCV is the reference library in
computer vision, it is open source and used extensively by both academia and business.
2
Chapter 2
Training
The purpose of this part is learning of OpenCV. No report will be requested or mark be attributed.
a frontlight,
a USB 2D camera embedded with a standard objective along with, or not, an extension tube,
depth of 8 bits,
USB2.0 output.
2, 3 and 4. For compatibility with the lab, it is recommended, if you wish to make a personal installation, to use
3
maximal working distance of innity.
Working distance can be modied for focusing purpose, assuming height of backlight is about
13.5 cm.
Copy, analyze and test the following code for reading a video stream until SPACE is clicked to stop:
"""
VISION 2D:
Training code
"""
import cv2
"""
Reading a video stream
"""
# Configure video stream source: 0 is the defaut one
cam = cv2.VideoCapture(0)
if (not cam.isOpened):
print ('Impossible to read the camera !')
# Display stream until clic on SPACE when mouse pointer in video display
while (True):
ret, frame = cam.read()
cv2.imshow('video', frame)
if cv2.waitKey(2)>=27:
break
# Deallocate memory
cam.release()
cv2.destroyAllWindows()
Listing 2.1: Python Code for reading a video stream
Use the image of a graduated ruler to estimate the maximum and minimum working distances,
and the minimum eld of view.
Therefore, compute the depth of eld, the maximum magnication and the minimum resolution.
4
2.2.3 Objective of 25 mm focal length with extension tube
Recalculate parameters: maximum and minimum working distances, minimum eld of view, depth
of eld, maximum magnication and minimum resolution.
Analyze the code then run it: during image display with imshow, the value of pixel under cursor
is displayed botton left.
"""
VISION 2D:
Training code
"""
import cv2
5
"""
Reading a single image
"""
# Read and display BGR image
bgr = cv2.imread ( './paperAppr.png', cv2.IMREAD_UNCHANGED )
if (not bgr.data):
print ('Impossible to read image !')
cv2.imshow("RGB image", bgr)
cv2.waitKey(0)
6
5. enhancement of grayscale image with morphological gradient (morphologyEx), Sobel gradient
(function Sobel) then with Canny gradient (function Canny).
7
Chapter 3
Testing
The purpose of this part is testing of your skills in computer vision through the use of OpenCV.
It is requested to supply a report describing the solution and the corresponding code. They will
be used for mark.
Some colored papers such that each paper has a unique uniform color are considered: pink,
purple, blue, green, orange, yellow and white (gure 3.1).
The papers move in a space structured in sectors numbered from top to bottom: 0 to 3.
The problem to solve consists in recognizing the color and position of the papers from their
images recorded in a video (paperEval.avi).
8
The image paperEval.png is provided for manual calibration of the sectors and colors, assum-
ing it is acquired in the same conditions as the video.
More precisely, the application should deliver per frame the following informations and save
them in a le resultats.txt: identication of any object by its appearance number in the image,
its color, the sector in which it (its center of inertia) is located (gure 3.2).