├── Face-recognition-project-based-on-Python-Opencv ├── 123.jpg ├── Blur and filtering ├── Brightness and contrast conversion ├── DIMOVERRIDE ├── Image cropping ├── Negative transformation ├── Noise processing ├── README.md └── Reading and storage based on OpenCV ├── Face-recognition-project-based-on-Python-face_recognition ├── Image segmentation ├── OlivettiFaces dataset and partitioning.zip ├── README.md └── gif转jpg └── README.md /Face-recognition-project-based-on-Python-Opencv/123.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cltcj/Face-recognition-project-based-on-Python/23f4450798a830d0f54fdb8d36147261ee93b632/Face-recognition-project-based-on-Python-Opencv/123.jpg -------------------------------------------------------------------------------- /Face-recognition-project-based-on-Python-Opencv/Blur and filtering: -------------------------------------------------------------------------------- 1 | # 姓名 : CLT 2 | # 开发时间 ;2021/4/21 0021 16:22 3 | #滤波方法:中值滤波、双边滤波、高斯模糊、二维卷积 4 | import cv2 5 | import numpy as np 6 | import random 7 | 8 | impulse_noise_image=cv2.imread('D:\\minote3\\200303\\impulse_noise.jpg') 9 | gaussian_noise_image=cv2.imread('D:\\minote3\\200303\\gaussian_noise.jpg') 10 | 11 | #二维卷积 12 | convolution_kernel=np.ones((5,5),np.float32)/25 13 | #print(convolution_kernel) 14 | convolution_2d_image=cv2.filter2D(impulse_noise_image,-1,convolution_kernel) 15 | cv2.imwrite('D:\\minote3\\200303\\convolution.jpg',convolution_2d_image) 16 | 17 | #中值滤波 18 | median_filter_image=cv2.medianBlur(impulse_noise_image,5) 19 | cv2.imwrite('D:\\minote3\\200303\\median filter.jpg',median_filter_image) 20 | 21 | #高斯模糊 22 | gaussian_blur_image=cv2.GaussianBlur(gaussian_noise_image,(5,5),0) 23 | cv2.imwrite('D:\\minote3\\200303\\gaussian blur.jpg',gaussian_blur_image) 24 | 25 | #双边滤波 26 | #cv2.bilateralFilter(src,d,sigmaColor,sigmaSpace) 27 | #9代表邻域直径,两个参数75分别代表值域与空域标准差 28 | bilateral_filter_image=cv2.bilateralFilter(gaussian_noise_image,9,75,75) 29 | cv2.imwrite('D:\\minote3\\200303\\bilateral filter.jpg',bilateral_filter_image) 30 | -------------------------------------------------------------------------------- /Face-recognition-project-based-on-Python-Opencv/Brightness and contrast conversion: -------------------------------------------------------------------------------- 1 | # 姓名 : CLT 2 | # 开发时间 ;2021/4/21 0021 16:22 3 | #滤波方法:中值滤波、双边滤波、高斯模糊、二维卷积 4 | import cv2 5 | import numpy as np 6 | 7 | #way1 8 | def convert_image1(image,alpha,beta): 9 | blank=np.zeros(image.shape,image.dtype) 10 | new_image1=cv2.addWeighted(image,alpha,blank,0,beta) 11 | return new_image1 12 | #cv2.addWeighted() 13 | 14 | #way2 15 | def convert_image2(image,alpha,beta): 16 | rows,cols,channel=image.shape#设置行,列,通道 17 | new_image_2=np.zeros(image.shape,image.dtype) 18 | print(image.shape) 19 | for i in range(0,rows):#720 20 | #print(i) 21 | for j in range(0,cols):#480 22 | for k in range(0,channel):#3 23 | #np.clip()将数值限制在[0,255]之间,防止数字溢出 24 | new_image_2[i,j,k]=np.clip(alpha*image[i,j,k]+beta,0,255) 25 | print(new_image_2) 26 | return new_image_2 27 | 28 | image=cv2.imread('D:\\minote3\\200303\\123.jpg') 29 | cv2.imwrite('D:\\minote3\\200303\\converted_1.jpg',convert_image1(image,2.2,50)) 30 | cv2.imwrite('D:\\minote3\\200303\\converted_2.jpg',convert_image2(image,2.2,50)) 31 | -------------------------------------------------------------------------------- /Face-recognition-project-based-on-Python-Opencv/DIMOVERRIDE: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | image=cv2.imread('D:\\minote3\\200303\\123.jpg') 4 | print(image.shape)#(3016, 4032, 3) 5 | new_image_1=cv2.resize(image,(1000,1200),interpolation=cv2.INTER_AREA) 6 | cv2.imwrite('D:\\minote3\\200303\\shrink.jpg',new_image_1) 7 | print(new_image_1.shape)#(1200, 1000, 3) 8 | new_image_2=cv2.resize(image,None,fx=0.5,fy=0.6,interpolation=cv2.INTER_AREA) 9 | #fx=0.5,fy=0.6--->x、y轴比例因子 10 | print(new_image_2.shape)#(1810, 2016, 3) 11 | cv2.imwrite('D:\\minote3\\200303\\shrink_1.jpg',image) 12 | -------------------------------------------------------------------------------- /Face-recognition-project-based-on-Python-Opencv/Image cropping: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | image=cv2.imread('D:\\minote3\\200303\\123.jpg') 4 | print(image.shape) 5 | new_image=image[100:3000,100:4000]#Trim from the 10th pixel to 100 pixels 6 | cv2.imwrite('D:\\minote3\\200303\\tailor.jpg',new_image) 7 | -------------------------------------------------------------------------------- /Face-recognition-project-based-on-Python-Opencv/Negative transformation: -------------------------------------------------------------------------------- 1 | # 姓名 : clt 2 | # 开发时间 ;2021/4/21 0021 8:51 3 | import cv2 4 | import numpy as np 5 | image=cv2.imread('D:\\minote3\\200303\\123.jpg') 6 | height=image.shape[0] 7 | width=image.shape[1] 8 | #print(image.shape) 9 | negative_file=np.zeros((height,width,3)) 10 | 11 | # Split the BGR image into three color channels. Note that the order of the color channels is blue, green, and red 12 | b,g,r=cv2.split(image) 13 | 14 | # to negatize processing, find each channel color complement 15 | r=255-r 16 | g=255-g 17 | b=255-b 18 | 19 | # Assigns the result of the processing to the previously generated 3D tensor 20 | negative_file[:,:,0]=b 21 | negative_file[:,:,1]=g 22 | negative_file[:,:,2]=r 23 | -------------------------------------------------------------------------------- /Face-recognition-project-based-on-Python-Opencv/Noise processing: -------------------------------------------------------------------------------- 1 | 2 | import numpy as np 3 | import cv2 4 | import random 5 | 6 | #Add salt and pepper noise 7 | def impulse_noise(image,percentage): 8 | ''' 9 | :param image:The original image 10 | :param percentage:Proportion of salt and pepper noise 11 | :return:Add salt and pepper 12 | ''' 13 | rows,cols=image.shape 14 | num=int(percentage*rows*cols) 15 | #print(num) 16 | for i in range(num): 17 | x=random.randint(0,rows-1) 18 | y=random.randint(0,cols-1) 19 | if random.randint(0,1)==0: 20 | image[x,y]=0 21 | else: 22 | image[x,y]=255 23 | return image 24 | 25 | 26 | #Gaussian noise 27 | def gaussian_noise(image,mean,sigma,k): 28 | ''' 29 | :param image:The original image 30 | :param mean: The mean value of a Gaussian distribution of random numbers 31 | :param sigma: σRepresents the standard deviation of the Gaussian distribution of random numbers 32 | :param k: Coefficient, expressed as Gaussian noise intensity 33 | :return:Returns the graph with Gaussian noise added 34 | ''' 35 | rows,cols=image.shape 36 | for i in range(rows): 37 | for j in range(cols): 38 | value=int(image[i,j]+k*random.gauss(mu=mean,sigma=sigma)) 39 | value=np.clip(a_max=255,a_min=0,a=value) 40 | image[i,j]=value 41 | return image 42 | image=cv2.imread('D:\\minote3\\200303\\123.jpg') 43 | 44 | gray_image=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) 45 | cv2.imwrite('gray.jpg',gray_image) 46 | gray_image_1=gray_image.copy() 47 | 48 | 49 | cv2.imwrite('D:\\minote3\\200303\\impulse_noise.jpg',impulse_noise(gray_image,0.3)) 50 | cv2.imwrite('D:\\minote3\\200303\\gaussian_noise.jpg',gaussian_noise(gray_image_1,0,1,32)) 51 | -------------------------------------------------------------------------------- /Face-recognition-project-based-on-Python-Opencv/README.md: -------------------------------------------------------------------------------- 1 | # Face-recognition-project-based-on-Python 2 | From theory to practice 3 | 123.jpg为初始处理图片 4 | 5 | 1.Negative transformation: 6 | 7 | negative 8 | 9 | In the earliest photographic film development, it refers to the image obtained after exposure and development. 10 | Negative operation is also called inverse color in many image processing software. Its light and shade are the opposite of the original image, and its color is the complementary color of the original image. 11 | #eg: Color A and color B are complementary colors. The sum of the two colors is 255, that is, the color of A point in the RGB image is (0,0,255), then the complementary color is (255,255,0). 12 | 13 | 2.Brightness and contrast conversion: 14 | 15 | In general, an image processing operator is a function that takes one or more images as input data and produces an output image. 16 | 17 | Image transformation can be divided into two types: 18 | 19 | 1) Point operator: Based on pixel transformation, in this kind of image transformation, the corresponding output pixel value is calculated only based on the input pixel value (sometimes with some additional information). 20 | 21 | 2) Neighborhood operator: Transform based on image region. 22 | 23 | Two commonly used operators are to multiply or add the pixel value of a point with a constant, which can be expressed as: 24 | # g (I, j) = alpha * f (I, j) + beta, among them, the neutral position as (I, j), alpha represents the gain, beta represents the offset.The image brightness and contrast transformation is a kind of point operator, these two parameters can control the contrast and brightness respectively 25 | #note: image pixel value range [0,255] 26 | 27 | 3.Noise processing: 28 | 29 | The less noise, the better the picture quality 30 | Image noise: that is, unnecessary or redundant information in image data 31 | 32 | Robustness: A system or organization has the ability to resist or overcome adverse conditions. When an algorithm model is said to be robust, it indicates that some abnormal data have little or no impact on the overall performance of the algorithm model. 33 | 34 | Adding appropriate amount of noise to the training data can make the trained model more robust and improve the performance of the model 35 | 36 | #------------- Add a noise TAB 37 | Pepper and salt noise: also known as impulse noise, is a kind of noise that is often seen in images. It is a random white or black dot, which may be black pixels in the bright area or white pixels in the dark area (or both). 38 | Salt and pepper noise can be caused by sudden and strong interference with the image signal, analog-to-digital converter or bit transmission errors, etc.For example, a failed sensor results in a minimum pixel value, and a saturated sensor results in a maximum pixel value. 39 | 40 | Add salt and pepper noise to image simulation is achieved by randomly acquiring pixel points and setting them as high brightness points and low gray pointsGaussian noise: Gaussian noise refers to a kind of noise whose high green density function obeys Gaussian distribution.In particular, if the amplitude distribution of a noise obeys the Gaussian distribution and its power spectral density is uniformly distributed, it is called the white Gaussian noise. 41 | 42 | The second moment of Gaussian white noise is uncorrelated, while the first moment is constant, which refers to the correlation of successive signals in time.Gaussian noise includes thermal noise and three-mile noise. 43 | Gaussian noise is determined by its mean value of events and the two instantaneous covariance function. If the noise is stationary, the mean value is independent of time, while the covariance function becomes a correlation function only related to the difference between the two instantaneous values under consideration, which is equivalent to the power spectral density in the sense. 44 | -------------------------------------------------------------------------------- /Face-recognition-project-based-on-Python-Opencv/Reading and storage based on OpenCV: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | image=cv2.imread('D:\\minote3\\200303\\123.jpg') 4 | print(image.shape) 5 | #print(image) 6 | #cv2.imwrite('D:\\minote3\\200303\\clt.jpg',image) 7 | 8 | gray_image=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) 9 | #cv2.cvtColor(p1,p2) 10 | print(gray_image.shape) 11 | image_BGR=cv2.cvtColor(gray_image,cv2.COLOR_GRAY2BGR) 12 | print(image_BGR) 13 | -------------------------------------------------------------------------------- /Face-recognition-project-based-on-Python-face_recognition/Image segmentation: -------------------------------------------------------------------------------- 1 | # 姓名 : 池吕庭 2 | # 开发时间 ;2021/4/23 0023 11:03 3 | import cv2 4 | import numpy as np 5 | import os 6 | from PIL import Image 7 | # data_dir="F:\face\olivettifaces" 8 | # image_name="olivettifaces.jpg" 9 | # image=cv2.imdecode(np.fromfile(os.path.join(data_dir,image_name),dtype=np.uint8),-1) 10 | # print(image.shape) 11 | # olivettifaces_image=cv2.imread(r"F:\\face\\olivettifaces\\olivettifaces.jpg") 12 | # imgae_save='r.F:\\face\\olivettifaces' 13 | # print(olivettifaces_image.shape) 14 | # data=cv2.cvtColor(olivettifaces_image,cv2.COLOR_BGR2GRAY) 15 | # faces={} 16 | # label=0 17 | # count=1 18 | # picture_list=[] 19 | # a=0 20 | # for row in range(20): 21 | # for column in range(20): 22 | # #image=picture_list.append(data[row*57:(row+1)*57,column*47:(column+1)*47]) 23 | # image= data[row*57:(row+1)*57,column*47:(column+1)*47] 24 | # 25 | # image.save("F:/face/olivettifaces" + str(row) + "/" + str(column) + ".jpg") 26 | # 27 | # #cv2.imwrite("F:/face/olivettifaces" + str(row) + "/" + str(column) + ".jpg", image) 28 | # # if count % 10 == 0 and count!=0: 29 | # # faces[label]=picture_list 30 | # # label+=1 31 | # # 32 | # # picture_list=[] 33 | # # count+=1 34 | # 35 | # 36 | # 37 | # 38 | # # cv2.imwrite('F:\\face\\olivettifaces',faces) 39 | import cv2 40 | import numpy as np 41 | 42 | def split_to_dataset(img_path, save_path): 43 | olive = cv2.imread(img_path) 44 | if olive is None: 45 | raise Exception("can not open the olivettifaces dataset file.") 46 | for row in range(20): 47 | for column in range(20): 48 | img = olive[row * 57:(row + 1) * 57, column * 47:(column + 1) * 47] 49 | cv2.imwrite(img=img, filename=save_path + "/" + str(row) + "_" + str(column) + ".jpg") 50 | split_to_dataset("F:\\face\\olivettifaces\\olivettifaces.jpg","F:\\face\\olivettifaces") 51 | 52 | -------------------------------------------------------------------------------- /Face-recognition-project-based-on-Python-face_recognition/OlivettiFaces dataset and partitioning.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cltcj/Face-recognition-project-based-on-Python/23f4450798a830d0f54fdb8d36147261ee93b632/Face-recognition-project-based-on-Python-face_recognition/OlivettiFaces dataset and partitioning.zip -------------------------------------------------------------------------------- /Face-recognition-project-based-on-Python-face_recognition/README.md: -------------------------------------------------------------------------------- 1 | # Face-recognition-project-based-on-Python 2 | #From theory to practice 3 | 4 | -------------------------------------------------------------------------------- /Face-recognition-project-based-on-Python-face_recognition/gif转jpg: -------------------------------------------------------------------------------- 1 | # 姓名 :CLT 2 | # 开发时间 ;2021/4/23 0023 11:35 3 | from PIL import Image 4 | im = Image.open('F:\\olivettifaces.gif') 5 | im = im.convert('RGB') 6 | def iter_frames(im): 7 | try: 8 | i= 0 9 | while 1: 10 | im.seek(i) 11 | imframe = im.copy() 12 | if i == 0: 13 | palette = imframe.getpalette() 14 | else: 15 | imframe.putpalette(palette) 16 | yield imframe 17 | i += 1 18 | except EOFError: 19 | pass 20 | for i, frame in enumerate(iter_frames(im)): 21 | frame.save('image.jpg',**frame.info) 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Face-recognition-project-based-on-Python 2 | #From theory to practice 3 | #Take a close look at each branch 4 | --------------------------------------------------------------------------------