def getimage(path): IDs=[] faces=[] imagepaths=[os.path.join(path,f) for f in os.listdir(path)] for imagepath in imagepaths: ID=int(os.path.split(imagepath)[-1].split('.')[0]) IDs.append(ID) faceimage=Image.open(imagepath).convert('L') faceNp=np.array(faceimage,'uint8') newfaceNp=cv2.resize(faceNp,None,300,300) faces.append(newfaceNp) cv2.imshow("Training",newfaceNp) cv2.waitKey(10) return np.array(IDs) , faces cv2.destroyAllwindow();
def getimage(path): IDs=[] faces=[] imagepaths=[os.path.join(path,f) for f in os.listdir(path)] for imagepath in imagepaths: if imagepath=="dataset\Thumbs.db": continue else: ID=int(os.path.split(imagepath)[-1].split('.')[0]) IDs.append(ID) faceimage=Image.open(imagepath).convert('L') faceNp=np.array(faceimage,'uint8') faces.append(faceNp) cv2.imshow("Training",faceNp) cv2.waitKey(10) return np.array(IDs) , faces cv2.destroyAllwindow();
import cv2 import sys import numpy as np windowname_in = "Example-in" windowname_out = "Example-out" ll = './image/adrian.jpg' img = cv2.imread(ll) cv2.imshow(windowname_in, img) out = np.zeros(img.shape, dtype=np.uint8) out = cv2.GaussianBlur(img, (3, 3), 0) cv2.imshow(windowname_out, out) cv2.waitKey(0) cv2.destroyAllwindow()
windowname_out = "Example-out" ll = './image/adrian.jpg' img = cv2.imread(ll) def doCanny(img,lowThresh,highThresh,aperture): width,height,channel = img.shape size = width,height,1 out = np.zeros(size,dtype=np.uint8) out = cv2.Canny(img,lowThresh,highThresh,aperture) return out def doPyrDown(img): width,height,channel = img.shape assert width%2 == 0 and height%2 == 0 , "error" size = width/2,height/2,channel out = np.zeros(size,dtype=np.uint8) cv2.pyrDown(img,out) return out out = doPyrDown(img) out = doPyrDown(out) out = doCanny(out,0,500,3) cv2.imshow(windowname_in,img) cv2.imshow(windowname_out,out) cv2.waitKey(0) cv2.destroyAllwindow()