def detect(gray, frame):
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2)
        roi_gray = gray[y:y + h, x:x + w]
        roi_color = frame[y:y + h, x:x + w]
        eyes = eye_cascade.detectMultiScale(roi_gray, 1.1, 3)
        for (ex, ey, ew, eh) in eyes:
            cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0),
                          2)
    return frame
Ejemplo n.º 2
0
def draw_rectangle(img, rect):
    (x, y, w, h) = rect
    cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
Ejemplo n.º 3
0
im2 = img.copy()

# A text file is created and flushed
file = open("recognized.txt", "w+")
file.write("")
file.close()

# Looping through the identified contours
# Then rectangular part is cropped and passed on
# to pytesseract for extracting text from it
# Extracted text is then written into the text file
for cnt in contours:
    x, y, w, h = cv.boundingRect(cnt)

    # Drawing a rectangle on copied image
    rect = cv.rectangle(im2, (x, y), (x + w, y + h), (0, 255, 0), 2)

    # Cropping the text block for giving input to OCR
    cropped = im2[y:y + h, x:x + w]

    # Open the file in append mode
    file = open("recognized.txt", "a")

    # Apply OCR on the cropped image
    text = pytesseract.image_to_string(cropped)

    # Appending the text into file
    file.write(text)
    file.write("\n")

    # Close the file
Ejemplo n.º 4
0
out = img.resize([int(reduced_percent * s) for s in img.size])
imagePath = "/sdcard/image.jpg"
out.save(imagePath)
sleep(3)
# Set the haarcascade file path
cascPath = "/sdcard/haarcascade_frontalface_default.xml"

# Create the haar cascade
faceCascade = cv2.CascadeClassifier(cascPath)

# Read the image
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Detect faces in the image
faces = faceCascade.detectMultiScale(gray,
                                     scaleFactor=1.2,
                                     minNeighbors=5,
                                     minSize=(30, 30),
                                     flags=cv2.cv.CV_HAAR_SCALE_IMAGE)

print("Found {0} faces!".format(len(faces)))

# Draw a rectangle around the faces
for (x, y, w, h) in faces:
    cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
#save the image
cv2.imwrite('/sdcard/out.jpg', image)
#display the image
droid.view("file:///sdcard/out.jpg", "image/*")
Ejemplo n.º 5
0
import cv
import time
import numpy as np

cv_car = cv.CascadeClassifier(
    r'C:\Users\DEBIPRASAD\Desktop\Projetc Work\ComputerVision-Projects-master\CarPedestrianDetection\cascades\haarcascade_car.xml'
)
capture = cv.VideoCapture(
    r'C:\Users\DEBIPRASAD\Desktop\Projetc Work\ComputerVision-Projects-master\CarPedestrianDetection\files\cars.avi'
)

while capture.isOpened():
    response, frame = capture.read()
    if response:
        gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
        cars = cv_car.detectMultiScale(gray, 1.2, 3)
        for (x, y, w, h) in cars:
            cv.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 0), 3)
            cv.imshow('cars', frame)
        if cv.waitkey(1) & 0xFF == ord('q'):
            break
    else:
        break
capture.release()
cv.destroyAllWindows()