0% found this document useful (0 votes)
25 views3 pages

Nama:Deden Diana (D111811068) Kelas: IF 5A 2018: Import

This document contains Python code to detect stop signs in images using OpenCV. It loads an image, converts it to grayscale, and uses a pre-trained classifier to detect any stop signs. For each sign detected, it draws a green rectangle around the sign in the original RGB image. It then displays the annotated image and waits for a key press before closing the window.

Uploaded by

Ilham abdulaziz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views3 pages

Nama:Deden Diana (D111811068) Kelas: IF 5A 2018: Import

This document contains Python code to detect stop signs in images using OpenCV. It loads an image, converts it to grayscale, and uses a pre-trained classifier to detect any stop signs. For each sign detected, it draws a green rectangle around the sign in the original RGB image. It then displays the annotated image and waits for a key press before closing the window.

Uploaded by

Ilham abdulaziz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Nama :Deden Diana (D111811068)

Kelas : IF 5A 2018

import cv2

# Opening image
img = cv2.imread("image1.jpg")

# OpenCV opens images as BRG
# but we want it as RGB We'll
# also need a grayscale version
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

# Use minSize because for not
# bothering with extra-small
# dots that would look like STOP signs
stop_data = cv2.CascadeClassifier('stop_data.xml')
found = stop_data.detectMultiScale(img_gray,
minSize =(20, 20))

# Don't do anything if there's
# no sign
amount_found = len(found)
if amount_found != 0:

 # There may be more than one
 # sign in the image
    for (x, y, width, height) in found:

 # We draw a green rectangle around
 # every recognized sign
        cv2.rectangle(img_rgb, (x, y),
        (x + height, y + width),
        (0, 255, 0), 5) 

# Creates the environment of
# the picture and shows it
cv2.imshow("Stop Sign",img_rgb)
cv2.waitKey(0) # waits until a key is pressed
cv2.destroyAllWindows() # destroys the window showing image

You might also like