当前位置:网站首页>给图片人脸部分加上马赛克
给图片人脸部分加上马赛克
2022-07-23 05:37:00 【mandala -chen】
前提
安装face_recognition 库 可参考这里
opencv 4.2
numpy
#给图片加马赛克
import cv2
import numpy as np
import pandas as pd
import os
from matplotlib import pyplot as plt
import face_recognition
img2=cv2.imread("3333.jpg")
img=cv2.imread("9k_.jpg")
#转换为灰度图
img2_gray = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
img2_face=face_recognition.face_locations(img2,number_of_times_to_upsample = 0,model ='cnn')
for (top,right,bottom,left) in img2_face:
#用矩形框标记出眼睛的位置 检测多尺度图像,返回值是一张脸部区域信息的列表(x,y,宽,高)
# cv2.rectangle(img2,(left,top),(right,bottom),(255,0,0),2)
roi_gray = img2_gray[top:bottom, left:right]
roi_color= img2[top:bottom, left:right]
img2=img2[top:bottom, left:right]
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces=face_recognition.face_locations(img,number_of_times_to_upsample = 0,model ='cnn')
#x left y top x+w right y+h bottom
for (top,right,bottom,left) in faces:
#用矩形框标记出眼睛的位置 检测多尺度图像,返回值是一张脸部区域信息的列表(x,y,宽,高)
# cv2.rectangle(img,(left,top),(right,bottom),(255,0,0),2)
height,width =[bottom-top,right-left]
img2 = cv2.resize(img2,(height , width),interpolation=cv2.INTER_AREA)
roi_gray = gray[top:bottom, left:right]
roi_color = img[top:bottom, left:right]
img[top:bottom, left:right]=img2
cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
效果如下:
边栏推荐
- 十年架构五年生活-02第一份工作
- Visual studio 2022 interesting and powerful intelligent auxiliary coding
- 【视觉SLAM】ORB-SLAM: Tracking and Mapping Recognizable Features
- Redis源码与设计剖析 -- 7.快速列表
- Deploy storageclass trample record
- 一次 MySQL 误操作导致的事故,「高可用」都不好使了
- Data Lake: introduction to Apache iceberg
- Cadence learning path (VIII) PCB placement components
- 达人专栏 | 还不会用 Apache Dolphinscheduler?大佬用时一个月写出的最全入门教程
- C language n battle -- linked list (IX)
猜你喜欢

C1--Vivado配置VS Code文本编辑器环境2022-07-21

Redis source code and design analysis -- 5. Integer set

部署storageclass踩坑记录

C1 -- vivado configuration vs code text editor environment 2022-07-21

Two strategies for building AI products / businesses (by Andrew ng)

Mysql事务回滚机制与原理

H1--HDMI接口测试应用2022-07-15

NOTIFIER诺帝菲尔消防主机电源维修及日常维护

Pyqt5 use qpainter to draw the coordinate axis and display the scatter diagram

Huck hurco industrial computer maintenance winmax CNC machine tool controller maintenance
随机推荐
Switch exchanges
单点登录-认证服务器与客户端的session过期时间如何统一
Single sign on - how to unify the expiration time of session between authentication server and client
Redis源码与设计剖析 -- 13.有序集合对象
Concepts et différences de bits, bits, octets et mots
Activiti工作流使用之项目实例
QT style syntax definition access, can check the data, can be automatically generated
Optimization Net application CPU and memory 11 practices
An accident caused by MySQL misoperation, and "high availability" is not working well
排序
6、重心坐标插值和图形渲染管线
Notifier Nordic fire engine power supply maintenance and daily maintenance
【达人专栏】还不会用Apache Dolphinscheduler吗,大佬用时一个月写出的最全入门教学【二】
9. Ray tracing
Dynamic memory management
C EventHandler observer mode
Murata power maintenance switch server power maintenance and main functional features
Why does MySQL index use b+ tree?
Heidelberg CP2000 circuit board maintenance printer host controller operation and maintenance precautions
PXE remote installation and kickstart unattended installation technical documents