2022-03-07 OpenCV 修饰证件照

image.png
# -*- coding: utf-8 -*-
"""
Created on Mon Mar  7 14:00:22 2022

@author: cyb20176
"""


import cv2
import numpy as np

img=cv2.imread(r'Quan_photo.jpg')
hsv=cv2.cvtColor(img,cv2.COLOR_BGR2HSV)

cv2.imshow('hsv',hsv)

# lower_blue=np.array([90,70,70])
# upper_blue=np.array([110,225,225])
lower_red=np.array([0,135,135])
upper_red=np.array([180,245,230])
mask=cv2.inRange(hsv,lower_red,upper_red)
cv2.imshow('Mask',mask)

rows,cols,channels=img.shape
for i in range(rows):
    for j in range(cols):
        if mask[i,j]==255:
            img[i,j]=(255,0,0)
        
cv2.imshow('res',img)
cv2.imwrite(r'C:\Users\cyb20176\Desktop\My photon\new2.jpg',img)
cv2.waitKey(0)
cv2.destroyAllWindow

你可能感兴趣的:(2022-03-07 OpenCV 修饰证件照)