当前位置:网站首页>给图片人脸部分加上马赛克
给图片人脸部分加上马赛克
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()
效果如下:
边栏推荐
- Mysql的索引为什么用的是B+树?
- Database process stuck solution
- Single sign on - how to unify the expiration time of session between authentication server and client
- Concepts and differences of bit, bit, byte and word
- 动态内存管理
- 【社媒营销】出海新思路:Whatsapp Business替代Facebook
- Visual studio 2022 interesting and powerful intelligent auxiliary coding
- Heidelberg CP2000 circuit board maintenance printer host controller operation and maintenance precautions
- H1 -- HDMI interface test application 2022-07-15
- IO should know and should know
猜你喜欢

Redis源码与设计剖析 -- 13.有序集合对象

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

FFmpeg 音频编码

9、光线追踪

3DMAX first skin brush weights, then attach merge

Deploy metersphere

Error in na.fail. default(list(Purchase = c(“CH“, “CH“, “CH“, “MM“, “CH“, : missing values in obj

SPR:SUPERVISED PERSONALIZED RANKING BASED ON PRIOR KNOWLEDGE FOR RECOMMENDATION

PyTorch(五)——PyTorch进阶训练技巧

Activiti工作流使用之Activiti-app的安装及流程创建
随机推荐
Pytorch (V) -- pytorch advanced training skills
讲师征集令 | Apache DolphinScheduler Meetup分享嘉宾,期待你的议题和声音!
9、光线追踪
MySql语句查询某一级节点的所有子节点
IO should know and should know
华为高层谈 35 岁危机,程序员如何破年龄之忧?
Redis源码与设计剖析 -- 11.哈希对象
Optimization Net application CPU and memory 11 practices
C语言n番战--结构体(七)
What does resource pooling and resource pooling mean?
Redis source code and design analysis -- 12. Collection objects
Recommend a shell installation force artifact, which has been open source! Netizen: really fragrant...
Error in na.fail. default(list(Purchase = c(“CH“, “CH“, “CH“, “MM“, “CH“, : missing values in obj
C1 -- vivado configuration vs code text editor environment 2022-07-21
Cadence (IX) 17.4 rules and spacing settings
Qt样式的语法定义获得途径,可查资料,可自动生成
Powerbi Getting Started Guide
[swift bug] Xcode prompt error running playground: failed to prepare for communication with playground
Deploy storageclass trample record
数据库进程卡住解决