import cv2
import
numpy
photo=numpy.zeros((500,500))
cv2.imshow('task1',photo)
cv2.waitKey()
cv2.destroyAllWindows()
cv2.imwrite('task1.jpg',photo)
photo=cv2.imread('task1.jpg')
photo.shape
photo=cv2.rectangle(photo,(120,160),(240,400),[120,56,135],10)
cv2.imshow('photo',photo)
cv2.waitKey()
cv2.destroyAllWindows()
lphoto = cv2.line(photo,(120,160),(180,80),[120,56,135],10)
inserting the shape of line into the image with function line(imagename,(x1-cordinate,y1-cordinate),[B,G,R],thickness)cv2.imshow('photo',lphoto)
cv2.waitKey()
cv2.destroyAllWindows()
lphoto1 = cv2.line(photo,(240,160),(180,80),[120,56,135],10)
cv2.imshow('photo',lphoto1)
cv2.waitKey()
cv2.destroyAllWindows()
rect=cv2.rectangle(lphoto1,(160,240),(200,400),[0,75,125],10)
cv2.imshow('photo',rect)
cv2.waitKey()
cv2.destroyAllWindows()
circle=cv2.circle(rect,(380,100),15,[253,250,211],100)
cv2.imshow('photo',circle)
cv2.waitKey()

--

--

HERE IS THE CODE….

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import cv2
import pytesseract

carplate_img = cv2.imread(‘./cars/car_image.png’)
carplate_img_rgb = cv2.cvtColor(carplate_img, cv2.COLOR_BGR2RGB)
plt.imshow(carplate_img_rgb)
carplate_haar_cascade = cv2.CascadeClassifier(‘haarcascade_russian_plate_number.xml’)
def carplate_detect(image):
carplate_overlay = image.copy()
carplate_rects = carplate_haar_cascade.detectMultiScale(carplate_overlay,scaleFactor=1.1, minNeighbors=3)
for x,y,w,h in carplate_rects:
cv2.rectangle(carplate_overlay, (x,y), (x+w,y+h), (255,0,0), 5)
return carplate_overlay
detected_carplate_img = carplate_detect(carplate_img_rgb)
plt.imshow(detected_carplate_img)
def carplate_extract(image):

carplate_rects = carplate_haar_cascade.detectMultiScale(image,scaleFactor=1.1, minNeighbors=5)
for x,y,w,h in carplate_rects:
carplate_img = image[y+15:y+h-10 ,x+15:x+w-20]
return carplate_img
def enlarge_img(image, scale_percent):
width = int(image.shape[1] * scale_percent / 100)
height = int(image.shape[0] *scale_percent / 100)
dim = (width, height)

resized_image = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
return resized_image
carplate_extract_img = carplate_extract(carplate_img_rgb)
carplate_extract_img = enlarge_img(carplate_extract_img, 150)
plt.imshow(carplate_extract_img);
carplate_extract_img_gray = cv2.cvtColor(carplate_extract_img, cv2.COLOR_RGB2GRAY)

plt.axis(‘off’)
plt.imshow(carplate_extract_img_gray, cmap = ‘gray’);
carplate_extract_img_gray_blur = cv2.medianBlur(carplate_extract_img_gray,3) # kernel size 3
plt.axis(‘off’)
plt.imshow(carplate_extract_img_gray_blur, cmap = ‘gray’);

import easyocr
reader=easyocr.Reader([‘en’])
result=reader.readtext(carplate_extract_img_gray_blur)
result

Thanks!!!

--

--