Giter Site home page Giter Site logo

hoanglehaithanh / traffic-sign-detection Goto Github PK

View Code? Open in Web Editor NEW
252.0 13.0 100.0 218.62 MB

Traffic signs detection and classification in real time

Home Page: https://www.hoanglehaithanh.com/project

License: MIT License

Python 100.00%
python opencv traffic-signs traffic-sign-classification traffic-sign-recognition machine-learning image-processing

traffic-sign-detection's Introduction

Traffic signs detection and classification in real time

A new version using SSD will be released this summer for anyone need higher accuracy detection method. Stay tuned for new update!

1. Description

This project is a traffic signs detection and classification system on videos using OpenCV. The detection phase uses Image Processing techniques that create contours on each video frame and find all ellipses or circles among those contours. They are marked as candidates for traffic signs.

Detection strategy:

  1. Increase the contrast and dynamic range of the video frame
  2. Remove unnecessary colors like green with HSV Color range
  3. Use Laplacian of Gaussian to display border of objects
  4. Make contours by Binarization.
  5. Detect ellipse-like and circle-like contours

In the next phase - classification phase, a list of images are created by cropping from the original frame based on candidates' coordinate. A pre-trained SVM model will classify these images to find out which type of traffic sign they are.

Currently supported traffic signs (The name of each sign's file is corresponding to their class in SVM): Note:

  • All signs which belong to class 8 and above are marked as OTHERS because a competition requires this. There is also a class 0 which are marked as non-traffic-sign
  • Only the biggest sign in the current frame is cropped and classified

The SVM Model is trained each time the main.py called, before the detection phase but I still save the model in data_svm.dat to implement the model-reload function in the future to avoid retraining phase.

If a traffic sign is detected, it will be tracked until it disappears or there is another bigger sign in the frame. The tracking method is Dense Optical Flow.

2. Prerequisites:

  • Python 3.5
  • OpenCV3
  • Imutils (usepip3 install imutils to install)

3. System structure

a. There are 3 python files as 3 modules:

Other files:

The Dataset folder contains images for training SVM models. There are 12 folders contains cropped images of traffic signs. Each folder is named as the class of the traffic signs it contains. The special 0 folder contains non-traffic-sign cropped images which can be recognized as traffic signs in the detection phase. Wrong detected traffic signs

The dataset is created by applying the detection phase on many videos with various parameters to mark all traffic signs and then manually separating them into their right classes.

Each time run the program, the dataset can be updated by checking all generated cropped images of detected traffic signs, then find all misclassified traffic signs.

4. Installation

There are two ways of running the program:

Use default arguments:

$python3 main.py

Use custom arguments:

$python3 main.py
optional arguments:
  -h, --help            show this help message and exit
  --file_name FILE_NAME
                        Video to be analyzed
  --min_size_components MIN_SIZE_COMPONENTS
                        Min size component to be reserved
  --similitary_contour_with_circle SIMILITARY_CONTOUR_WITH_CIRCLE
                        Similarly to a circle

5. Result

6. Disadvantages

  • Static image processing, this means parameters must be updated for each video with different lighting conditions
  • The accuracy of the detection phase is not high, still, miss signs or detect wrong areas.
  • The dataset is a little bit overfitting for classification phase.

7. Future developments

  • Better performance with higher framerate
  • Use other approaches like YOLO or SSD
  • Dynamic image processing
  • Use CNN to classification
  • No need to retrain the model when running the program
  • Make a bigger dataset

8. License

MIT License © 2018 Hoàng Lê Hải Thanh (Thanh Hoang Le Hai) aka GhostBB

traffic-sign-detection's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

traffic-sign-detection's Issues

Error while running main.py

>python main.py
Loading data from data.png ...
./dataset/0/(1).png
./dataset/0/(10).png
.
.
.
.
./dataset/12/(163).png
./dataset/12/(164).png
(1469, 32, 32)
Shuffle data ...
Deskew images ...
Defining HoG parameters ...
Calculating HoG descriptor for every image ...
Spliting data into training (90%) and test set (10%)...
Training SVM model ...
Saving SVM model ...
Frame:0
Traceback (most recent call last):
  File "main.py", line 384, in <module>
    main(args)
  File "main.py", line 272, in main
    coordinate, image, sign_type, text = localization(frame, args.min_size_components, args.similitary_contour_with_circle, model, count, current_sign)
  File "main.py", line 171, in localization
    sign, coordinate = findLargestSign(original_image, contours, similitary_contour_with_circle, 15)
  File "main.py", line 122, in findLargestSign
    M = cv2.moments(c)
cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-wwma2wne\opencv\modules\imgproc\src\moments.cpp:602: error: (-210:Unsupported format or combination of formats)  in function 'cv::moments'

Could you help me out with this problem?

Issue with detecting a particular sign

Hi
I have run the main.py file with the sample video and encountered the an error. The program could correctly predict the first two signs(one way, speed limit 30) of the video but when it tries to predict the third sign(right turn) it fails and throws the below error.

File "main.py", line 316, in main
roi = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)
cv2.error: OpenCV(3.4.8) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

I have noticed that the roi value for that third image has become empty roi=[]

roi = frame[tl[1]:br[1], tl[0]:br[0]]
print('roi=======', roi) // here it is empty
roi = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)

Please help to resolve this issue.

error: (-210:Unsupported format or combination of formats) in function 'cv::moments'

Hi! I'm getting the following error when trying to run the code using your video:

Frame:0 Traceback (most recent call last): File "main.py", line 384, in <module> main(args) File "main.py", line 272, in main coordinate, image, sign_type, text = localization(frame, args.min_size_components, args.similitary_contour_with_circle, model, count, current_sign) File "main.py", line 171, in localization sign, coordinate = findLargestSign(original_image, contours, similitary_contour_with_circle, 15) File "main.py", line 122, in findLargestSign M = cv2.moments(c) cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\moments.cpp:696: error: (-210:Unsupported format or combination of formats) in function 'cv::moments'

Do you have any idea what's wrong?

Thanks!

ERROR <class 'cv2.VideoWriter'> returned a result with an error set

HI when i am trying to run the program i am getting an error \

cv2.error: C:\projects\opencv-python\opencv\modules\videoio\src\cap.cpp:389: error: (-215) result || fps != 0 in function cvCreateVideoWriterWithPreference


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "G:\Downloads\Traffic-Sign-Classification-master (1)\Traffic-Sign-Classification-master\main.py", line 384, in <module>
    main(args)
  File "G:\Downloads\Traffic-Sign-Classification-master (1)\Traffic-Sign-Classification-master\main.py", line 241, in main
    out = cv2.VideoWriter('output.avi',fourcc, fps , (640,480))
SystemError: <class 'cv2.VideoWriter'> returned a result with an error set

please help

error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

I'm having this problem executing the code: (Tested on windows and linux with opencv 3.4.4)

Traceback (most recent call last):
File "main.py", line 387, in
main(args)
File "main.py", line 299, in main
roi = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)
cv2.error: OpenCV(3.4.4) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

getting error in cv2.moments function

error: (-210:Unsupported format or combination of formats) in function 'cv::moments'
whole program run properly but it show error
File "E:\AutoCar\Traffic-Sign-Detection-master\main.py", line 384, in
main(args)
File "E:\AutoCar\Traffic-Sign-Detection-master\main.py", line 272, in main
coordinate, image, sign_type, text = localization(frame, args.min_size_components, args.similitary_contour_with_circle, model, count, current_sign)
File "E:\AutoCar\Traffic-Sign-Detection-master\main.py", line 171, in localization
sign, coordinate = findLargestSign(original_image, contours, similitary_contour_with_circle, 15)
File "E:\AutoCar\Traffic-Sign-Detection-master\main.py", line 122, in findLargestSign
M = cv2.moments(c)
cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\moments.cpp:696: error: (-210:Unsupported format or combination of formats) in function 'cv::moments'
please help me ASAP

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.