Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In the remainder of this lab, you employ the Pair Programming technique again. I

ID: 3706072 • Letter: I

Question

In the remainder of this lab, you employ the Pair Programming technique again. In pair programming, two programmers share a single computer with one programmer acting as the driver and the other acting as the navigator. The driver controls the keyboard and mouse while the navigator observes, asks questions, suggests solutions, and thinks about slightly longer-term strategies. The roles are swapped frequently This lab will be conducted in pairs so that you can practice your pair programing skills. You will find a partner to work with during this lab assignment. While you are working with your partner, these are the guidelines to follow: . Each pair will submit one lab solution marked with both partners names. Only one person will need to submit the program electronically One partner will start out being the driver while the other partner will start out being the navigator. Every 15 minutes, the instructor will make an announcement asking the drivers to switch roles with the navigators. The navigator is not allowed to touch the computeir In this Lab we will fix "redEye.jpg" in a similar way we d when we fixed "jenny-red.jpg". Programming Task (100 points) ye.jpg" from Blackboard. 1- Download the picture "rede 2- Startup JES, and Use MediaTools to find th values for startX,startY,endX, and endY. (You will need to pick the picture file first, then make it a picture) 3- We will try to modify function "removeRedEye " (Slide Ch05-2, page 13). Change the name for the function to "removeRedEyeLabO" 4- Your function "removeRedEyeLab0" must show a fixed picture (no red eyes anymore!). 5- Make sure that you include comments at the top of your program with Team members names Today's date Lab Number e appropriate

Explanation / Answer

#Import
import cv2
import numpy as np

#read image
img = cv2.imread("redeye.jpg")
outImage = img.copy()

# Load HAAR cascade
eyesCascade = cv2.CascadeClassifier("haarcascade_eye.xml")
eyeRects = eyesCascade.detectMultiScale(img , 1.1, 5 )
for x,y,w,h in eyeRects:
eyeImage = img [y:y+h , x:x+w]
b, g ,r = cv2.split(eyeImage)
bg = cv2.add(b,g)
mask = ( (r>(bg-20)) & (r>80) ).astype(np.uint8)*255
contours, _ = cv2. findContours(mask.copy() ,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE ) # It return contours and Hierarchy

#find contour with max Area
maxArea = 0
maxCont = None
for cont in contours:
area = cv2.contourArea(cont)
if area > maxArea:
maxArea = area
maxCont = cont
mask = mask * 0  
cv2.drawContours(mask , [maxCont],0 ,(255),-1 )
  
mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, cv2.getStructuringElement(cv2.MORPH_DILATE,(5,5)) )
mask = cv2.dilate(mask , (3,3) ,iterations=3)
mean = bg /2

  
mean = cv2.bitwise_and(mean , mask )  
mean = cv2.cvtColor(mean ,cv2.COLOR_GRAY2BGR )
mask = cv2.cvtColor(mask ,cv2.COLOR_GRAY2BGR )  
eye = cv2.bitwise_and(~mask,eyeImage)+mean
outImage [y:y+h , x:x+w] = eye
result = np.hstack((img,outImage))

#Display the Result
cv2.imshow("RedEyeCorrection" , result )
cv2.waitKey() # Wait for a keyPress
cv2.destroyAllWindows()