# loop over the face parts individually for (name, (i, j)) in face_utils.FACIAL_LANDMARKS_IDXS.items(): # clone the original image so we can draw on it, then # display the name of the face part on the image clone = frame.copy() cv2.putText(clone, name, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2) # loop over the subset of facial landmarks, drawing the # specific face part for (x, y) in shape[i:j]: cv2.circle(clone, (x, y), 1, (0, 0, 255), -1) # extract the ROI of the face region as a separate image (x, y, w, h) = cv2.boundingRect(np.array([shape[i:j]])) roi = frame[y:y + h, x:x + w] roi = imutils.resize(roi, width=250, inter=cv2.INTER_CUBIC) # show the particular face part cv2.imshow("ROI", roi) cv2.imshow("Image", clone) cv2.waitKey(0) # visualize all facial landmarks with a transparent overlay output = face_utils.visualize_facial_landmarks(frame, shape) cv2.imshow("Image", output) cv2.waitKey(0) # # show the image # cv2.imshow(winname="Face", mat=frame) # # # Exit when escape is pressed # if cv2.waitKey(delay=1) == 27: # break
while True: counter = 0 extraSpace = 110 lineBarrier = 60 output = np.zeros((h + extraSpace, w * 2, 3), 'uint8') timeStamps = np.zeros((2, 1)) if not np.count_nonzero(bkgd) and trackingToggle: cv2.namedWindow('selectBackground') cv2.setMouseCallback('selectBackground', buttonHandler) bkgdOutput = np.zeros((h + extraSpace, w * 2, 3), 'uint8') counter = 0 for stream in camList: frame = stream.read() frame = imutils.resize(frame, width=w, height=h) bkgdOutput[0:h, w * counter:w * (counter + 1)] = frame counter += 1 cv2.putText(bkgdOutput, 'Press the "1" key to take a background image', (40, h + int(6 * extraSpace / 10)), cv2.FONT_HERSHEY_SIMPLEX, .75, (255, 255, 255), 1) overlay = bkgdOutput.copy() bkgdOutputCopy = bkgdOutput.copy() cv2.rectangle(overlay, (2 * w - 25, h - 25), (2 * w, h - 1), (150, 150, 150), -1) cv2.rectangle(overlay, (2 * w - 25, h - 25), (2 * w, h - 1), (255, 255, 255), 1) cv2.putText(overlay, '< >', (2 * w - 20, h - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.25, (255, 255, 255), 2) cv2.addWeighted(overlay, buttonAlpha, bkgdOutputCopy, 1 - buttonAlpha,
import numpy as np import cv2 from imutils import imutils # translations image = cv2.imread( "/home/mmc/code/python_opencv/Books/Practical Python and OpenCV, 3rd Edition/code/images/trex.png" ) M = np.float32([[1, 0, 25], [0, 1, 50]]) shifted = cv2.warpAffine(image, M, (image.shape[1], image.shape[0])) cv2.imshow("Shifted Down and Right", shifted) M = np.float32([[1, 0, -50], [0, 1, -90]]) shifted = cv2.warpAffine(image, M, (image.shape[1], image.shape[0])) cv2.imshow("Shifted Up and Left", shifted) shifted = imutils.translate(image, 0, 100) cv2.imshow('Shifted Down', shifted) cv2.imshow('Original', image) im_resized = imutils.resize(image, width=100) cv2.imshow('Resized', im_resized)