[英]How to change color to specific portion of an image in opencv python?
I have an image of front facing man in which: 我有一个正面人的形象,其中:
1) I used facial landmark detection to detect the chin point. 1)我使用面部标志检测来检测下巴点。
2) Add some specific value to lower its y-coordinate value. 2)添加一些特定值以降低其y坐标值。
3) Find out the width of image. 3)找出图像的宽度。
4) Draw an line through the point. 4)通过该点画一条线。
Now, what I want to do is change the color to portion of image below the yellow line to white color, so that I could have a whole separated head only. 现在,我要做的就是将颜色从黄线以下的图像部分更改为白色,以便我只能将整个头分开。 How to do that? 怎么做?
Code I have done till now: 我到目前为止所完成的代码:
import cv2
import numpy as np
import dlib
img1 = cv2.imread('Test.jpg')
#Facial Landmark Detection
predictor_path = "C:\\Users\\G7K4\\Desktop\\BackEnd_New\\01 HeadSwap\\shape_predictor_68_face_landmarks.dat"
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(predictor_path)
img2 = detector(img1)
for k, d in enumerate(img2):
shape = predictor(img1, d)
vec = np.empty([68, 2], dtype = int)
for b in range(68):
vec[b][0] = shape.part(b).x
vec[b][1] = shape.part(b).y
SampleHead_chinPoint = (vec[8,0], vec[8,1])
print(SampleHead_chinPoint )
a = SampleHead_chinPoint[0]
b = SampleHead_chinPoint[1]
c = b + 25
cv2.circle(img1, (a, c), 5, (0,0,255), -1)
cv2.imshow("Pointed", img1)
cv2.waitKey(0)
width = img1.shape[1]
cv2.line(img1, (0,c), (width, c), (0, 255, 255), 2)
cv2.imshow("Lined", img1)
cv2.waitKey(0)
cv2.destroyAllWindows()
Images: 图片:
Original Image: 原始图片:
Output 1: 输出1:
Output 2: 输出2:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.