[Solved]Following Working Python Program Change Detectwinkpy Import Numpy Np Import Cv2 Import Os Q37209482


The following is the working python program to change,DetectWink.py:
import numpy as np
import cv2
import os
from os import listdir
from os.path import isfile, join
import sys
def detectWink(frame, location, ROI, cascade):
eyes = cascade.detectMultiScale(
ROI, 1.15, 3, 0|cv2.CASCADE_SCALE_IMAGE, (10, 20))
for e in eyes:
e[0] += location[0]
e[1] += location[1]
x, y, w, h = e[0], e[1], e[2], e[3]
cv2.rectangle(frame, (x,y), (x+w,y+h), (0, 0, 255), 2)
return len(eyes) == 1 # number of eyes is one
def detect(frame, faceCascade, eyesCascade):
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# possible frame pre-processing:
# gray_frame = cv2.equalizeHist(gray_frame)
# gray_frame = cv2.medianBlur(gray_frame, 5)
scaleFactor = 1.15 # range is from 1 to ..
minNeighbors = 3 # range is from 0 to ..
flag = 0|cv2.CASCADE_SCALE_IMAGE # either 0 or0|cv2.CASCADE_SCALE_IMAGE
minSize = (30,30) # range is from (0,0) to ..
faces = faceCascade.detectMultiScale(
gray_frame,
scaleFactor,
minNeighbors,
flag,
minSize)
detected = 0
for f in faces:
x, y, w, h = f[0], f[1], f[2], f[3]
faceROI = gray_frame[y:y+h, x:x+w]
if detectWink(frame, (x, y), faceROI, eyesCascade):
detected += 1
cv2.rectangle(frame, (x,y), (x+w,y+h), (255, 0, 0), 2)
else:
cv2.rectangle(frame, (x,y), (x+w,y+h), (0, 255, 0), 2)
return detected
def run_on_folder(cascade1, cascade2, folder):
if(folder[-1] != “/”):
folder = folder + “/”
files = [join(folder,f) for f in listdir(folder) ifisfile(join(folder,f))]
windowName = None
totalCount = 0
for f in files:
img = cv2.imread(f)
if type(img) is np.ndarray:
lCnt = detect(img, cascade1, cascade2)
totalCount += lCnt
if windowName != None:
cv2.destroyWindow(windowName)
windowName = f
cv2.namedWindow(windowName, cv2.WINDOW_AUTOSIZE)
cv2.imshow(windowName, img)
cv2.waitKey(0)
return totalCount
def runonVideo(face_cascade, eyes_cascade):
videocapture = cv2.VideoCapture(0)
if not videocapture.isOpened():
print(“Can’t open default video camera!”)
exit()
windowName = “Live Video”
showlive = True
while(showlive):
ret, frame = videocapture.read()
if not ret:
print(“Can’t capture frame”)
exit()
detect(frame, face_cascade, eyes_cascade)
cv2.imshow(windowName, frame)
if cv2.waitKey(30) >= 0:
showlive = False
# outside the while loop
videocapture.release()
cv2.destroyAllWindows()
if __name__ == “__main__”:
# check command line arguments: nothing or a folderpath
if len(sys.argv) != 1 and len(sys.argv) != 2:
print(sys.argv[0] + “: got ” + len(sys.argv) – 1
+ “arguments. Expecting 0 or 1:[image-folder]”)
exit()
# load pretrained cascades
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades
+ ‘haarcascade_frontalface_default.xml’)
eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades
+ ‘haarcascade_eye.xml’)
if(len(sys.argv) == 2): # one argument
folderName = sys.argv[1]
detections = run_on_folder(face_cascade, eye_cascade,folderName)
print(“Total of “, detections, “detections”)
else: # no arguments
runonVideo(face_cascade, eye_cascade)
EDIT: The module ‘cv2’ can be imported by installing thepackage, ‘opencv-python’ in the project interpreter

Object Detection Project In this project you are asked to write two programs to detect “winking”. In writing your programs you may use all of the high level functionality of OpenCV, but you are not allowed to convert images into arrays of pixel values. The only cascade classifiers that can be used are those provided by OpenCV, as well as those available in the following link http://alereimondo.no-ip.org/OpenCV/34 The cascade classifiers provided by OpenCV can be found in https://github.com/opencv/opencv/tree/master/data/haarcascades They are also available as part of the OpenCV distribution. If you have a mac, they are most likely in the following folder /Library/Frameworks/Python. framework/Versions/3.6/lib/python3.6/ site-packages/cv2/data/ On windows they may be in following folders C:/opencv/build/etc/haarcascades C:/opencv/sources/data/haarcascades C:/Users/name/AppData/Local/Programs/Python/Python35/Lib/site -packages/cv2/data The input to each program is a folder containing images or a live video feed. The progranm displays each image, and marks each detected face with a distinct color. It also computes and prints the total number of detections First program: DetectWink1.py Write an OpenCV program that can detect a winking face. You may want to build your program by changing the example program DetectWink.py Second program:Detect Wink2.py The requirements for the second program are the same as the requirements for the first program, except that it must start by applying a filter to the image. The filter can be histogram equalization, smoothing, or anything else that you may consider to be useful Suggestion of changes 1. Changing the parameters of the functions 2. Including or changing different preprocessing steps 3. Changing region of interest 4. Changing the logic of the program. 5. Anything else which would improve the correct detection and reduce the incorrect detections. What you need to submit 1. Python source code of your programs. Please name them DetectWinkl.py and DetectWink2.ру. Available Packages opencv mosaicoae-lIb-C-opencv opencv-contrib-python opencv-contrib-python-headless opencv-cython opencv-draw-tools-fernaperg opencv-lav Description Wrapper package for OpenCV python bindings Version 4.1.0.25 https:/lgithub.com/skvark/opencv-python encv-python opencv-python-aarch64 opencv-python-armv7l opencv-python-headless opencv-python-inference-engine opencv-rolling-ball opencv-utils opencv-wrapper opencv_cffi opencv_engine opencv_helpers opencvcontribpython opencvpython opencvutils pyopencv pypylon-opencV-viewer scikit-surgeryopencvcpp simple-opencv-ocr thumbor-engine-opencv tvl-backends-opencv Specify version 4.1.0.25 Options Install to user’s site packages directory (/Users/Fedolodic/.local) Install Package Manage Repositories Show transcribed image text Object Detection Project In this project you are asked to write two programs to detect “winking”. In writing your programs you may use all of the high level functionality of OpenCV, but you are not allowed to convert images into arrays of pixel values. The only cascade classifiers that can be used are those provided by OpenCV, as well as those available in the following link http://alereimondo.no-ip.org/OpenCV/34 The cascade classifiers provided by OpenCV can be found in https://github.com/opencv/opencv/tree/master/data/haarcascades They are also available as part of the OpenCV distribution. If you have a mac, they are most likely in the following folder /Library/Frameworks/Python. framework/Versions/3.6/lib/python3.6/ site-packages/cv2/data/ On windows they may be in following folders C:/opencv/build/etc/haarcascades C:/opencv/sources/data/haarcascades C:/Users/name/AppData/Local/Programs/Python/Python35/Lib/site -packages/cv2/data The input to each program is a folder containing images or a live video feed. The progranm displays each image, and marks each detected face with a distinct color. It also computes and prints the total number of detections First program: DetectWink1.py Write an OpenCV program that can detect a winking face. You may want to build your program by changing the example program DetectWink.py Second program:Detect Wink2.py The requirements for the second program are the same as the requirements for the first program, except that it must start by applying a filter to the image. The filter can be histogram equalization, smoothing, or anything else that you may consider to be useful Suggestion of changes 1. Changing the parameters of the functions 2. Including or changing different preprocessing steps
3. Changing region of interest 4. Changing the logic of the program. 5. Anything else which would improve the correct detection and reduce the incorrect detections. What you need to submit 1. Python source code of your programs. Please name them DetectWinkl.py and DetectWink2.ру.
Available Packages opencv mosaicoae-lIb-C-opencv opencv-contrib-python opencv-contrib-python-headless opencv-cython opencv-draw-tools-fernaperg opencv-lav Description Wrapper package for OpenCV python bindings Version 4.1.0.25 https:/lgithub.com/skvark/opencv-python encv-python opencv-python-aarch64 opencv-python-armv7l opencv-python-headless opencv-python-inference-engine opencv-rolling-ball opencv-utils opencv-wrapper opencv_cffi opencv_engine opencv_helpers opencvcontribpython opencvpython opencvutils pyopencv pypylon-opencV-viewer scikit-surgeryopencvcpp simple-opencv-ocr thumbor-engine-opencv tvl-backends-opencv Specify version 4.1.0.25 Options Install to user’s site packages directory (/Users/Fedolodic/.local) Install Package Manage Repositories
Expert Answer
Answer to The following is the working python program to change, DetectWink.py: import numpy as np import cv2 import os from os im… . . .
OR

