简体   繁体   English

如何在opencv python中将颜色更改为图像的特定部分?

[英]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: 原始图片:

test.jpg放在

Output 1: 输出1:

尖

Output 2: 输出2:

夹

Assumpt you have the chin point. 假设你有问题。

import cv2

img = cv2.imread("2.png")

chin_point = (370,230)

img[chin_point[0]:,:] = [255,255,255]

cv2.imshow("img", img)    

cv2.waitKey()
cv2.destroyAllWindows() 

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改 window (Python) (Tkinter) 特定部分的背景颜色 - How to change background color for a specific portion of window (Python) (Tkinter) 如何更改 Python 中特定坐标的像素颜色 3 | OpenCV? - How to change the color of pixels with Specific coordinates in Python 3 | OpenCV? Python:如何使用opencv在边框之间选择一部分图像 - Python:How to select a portion of image between a border using opencv OpenCV Python将图像的某些部分复制到另一部分 - OpenCV Python copying certain portion of image to another 如何使用 Python OpenCV 将颜色提取图像更改为相同颜色? - How do I change the color extracted image to the same color with Python OpenCV? 如何使用opencv python将黑色更改为红色 - how to change the black color to Red with opencv python Python:根据深色图像上的特定颜色绘制矩形周围的轮廓(OpenCV) - Python: Contour around rectangle based on specific color on a dark image (OpenCV) 使用python中的opencv在图像中的特定颜色周围显示边界 - To show a boundary around a specific color in a image using opencv in python 获取图像中具有特定颜色的像素数量。 Python, opencv - Get a quanity of pixels with specific color at image. Python, opencv Python:如何从图像中切出具有特定颜色的区域(OpenCV、Numpy) - Python: How to cut out an area with specific color from image (OpenCV, Numpy)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM