Sunteți pe pagina 1din 11

Object detection

Mezzi Houssem
summary
• In this rapport I will explain different parts of the code and explain all
predefined functions used in this code.
• In this code I used the OpenCV library to detect objects by their contours
and draw bounding boxes on each contour.
• After I crop those boxes, put them in a TensorFlow model for classification
and draw the prediction
Object detection with opencv
• As I said we are going to detect an object by contours but before finding
contours we need to prepare the image to reduce noise and detect all
contours desired.
• I used some techniques to improve the performance of the detector such as
using filters and detection edges before contours where I'm going to explain
it next.
• The first line is to convert the image to gray
• The second line is to smooth the image to reduce some noise and we can
control it by the kernel size set in the second function's arguments (7,7)
• Smoothing helps in reducing but not enough so this is why we need another
filter calls dilation.
• Dilation adds pixels to the boundaries of objects in an image so we need that
in the next parts when we detect edges.
• In this part, we detect edges a popular edge detection algorithm calls Canny
and we can control it by X and Y gradients values.
• We can easily see that still some noise and edges not connected these cause
problems when we detect contours,this is why I add another filter calls
closing.
• Closing is a Dilation followed by erosion, it helps us to connect contours.
Finding countours
• Contours can be explained simply as a curve joining all the continuous points
(along the boundary), having same color or intensity.
• cv.findContours() is a function, first one is source image, second is contour
retrieval mode, third is contour approximation method. And it outputs a
modified image, the contours and hierarchy. contours is a Python list of all
the contours in the image. Each individual contour is a Numpy array of (x,y)
coordinates of boundary points of the object.
• BoundingRect() the function calculates and returns the minimal up-right
bounding rectangle for the specified point set or non-zero pixels of the gray-
scale image.
• In the for loop we draw the rectangle for each contour.
• Finally, we crop each box, recise it and reshape it to the right format for the
classifier then we get the prediction.
The video with the file is real time test with my
laptop.

S-ar putea să vă placă și