P3B Car junction
In this practise we have to make able out car to negociate a car junction. So in order to make this practise let's divide it in some parts:
1. Detect stop signal
2. Look both sides
3. Turn left
1. Detect stop signal
First of all we have to make able our car to stop when it reach the stop signal. The car would have a constant lineal velocity and when it detects de stop signal it will start decelerating.
To detect the stop firstly i used a red colour filter, but there are some building that also have red parts so the car detect a red signal when it really wasn't.
In order to detect truely the stop signal, once the color filter detect something i compare it (cropping it with it's bounding box) with the shape of a true stop signal.
The function i use to compare the detected object with the true shape of a stop signal is cv2.subtract (make sure both image you compare has the same size, if not it will return an error). Then i count the number of pixels equal to zero (the ones that are equal to zero are the pixels that are the same in both images). If the number of zeros is more than x it means that the object detected is a stop signal.
Great! we now are able to detect the stop signal, but how we decelerate?
Once the car detects the stop signal it will start decreasing the velocity.
As the stop sign gets larger and larger the velocity will decrease more and more. For this i use the height and width of the bounding box (i get for compare the iamges) and calculate the total
area = height*width.
I multiply this area by a constant, obtaining a "slow" value which means how much im going to decrease the initial velocity.
If this "slow" value gives the car a negative velocity it will command velocity of 1, insterad of a negative number (to avoid weird behaviours). Same happens if gives the car a velocity lower than 1.
Also if the area is greater than x it means its time to stop, so the car will stop directly (not slow), commanding a zero velocity.
Here you have an example of this behaviour:
2. Look both sides
Now that the car is positioned at the stop it have to look to both sides to know if there is any car coming before decide to turn to the left.
To resolve this im going to detect if there is any movement in the left or right camera.
First i convert the image of both cameras to Gray then i applied a GaussianBlur to smooth the image. With this image prepared im going to compare this frame with the last image obtained in the last iteration.
To compare both i use cv2.absdiff, which return the difference between two images passed as arguments.
Then to the image that cv2.absdiff return i apply a morphological operation to remove all the noise and have a more solid image of the objects that has moved between the two frames. Then applying a threshold i convert all the pixels which are greater than x to 255 i get the final image where the car can see clearly if there is any car coming or not.
Once the car is able to "see" other cars with the bounding box of bouth sides if it's area is greater than x it won't cross. If the area is small and they are moving away from the crossroad it could cross.
To now if they are smaller than the las iteration i compare bouth bounding boxes the ones that the car is detecting and the area of the bounding boxes of the previous iteration.
I have problems with this part of the practise, becouse i wasn't able to detect only the cars, the movement filter gave me more things that were statical. So i couldn't get the bounf¡ding boxes of the movement objects (in this case the cars) so the car can't cross the road.
Here you have a demostration of how far i went:
Comentarios
Publicar un comentario