[英]Trying to blur the background of the image and bring a rectangular box on the face using python
我試圖首先在圖像的表面上放置一個矩形框,然后我試圖在(幀變量)中模糊圖像的背景並在(人臉變量)中提取人臉在執行代碼時出現錯誤:未定義幀.
import cv2
import matplotlib.pyplot as plt
image = cv2.imread('C:/Users/HP/l.jpg')
#image=cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image1 = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# Load the cascade
detector = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
plt.imshow(image1)
faces = detector.detectMultiScale(
image,
scaleFactor=1.2,
minNeighbors=10,
minSize=(10, 50),
)
for (x, y, w, h) in faces:
cv2.rectangle(image1, (x, y), (x+w, y+h), (1, 255, 4), 10)
face=image1[y:y+h,x:x+w]
frame=cv2.blur(image1,ksize = (10,10))
frame[y:y+h,x:x+w]=face
plt.imshow(frame)
plt.show()
plt.imshow(face)
plt.show()
它工作正常只檢查圖像是否實際上在提供的路徑中,因為它可能是圖像錯誤嘗試在文件中創建一個文件夾,您將圖像作為圖像運行,然后替換cv2.imread('\images\imagename.jpg')而不是這個cv2.imread('C:/Users/HP/l.jpg')圖像
import cv2
import matplotlib.pyplot as plt
#image = cv2.imread('C:/Users/HP/l.jpg')
image = cv2.imread('images/1,jpg')
#image=cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image1 = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.