如何统一颜色和文字

2024-10-01 19:14:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用在这里打开简历是原始图像 enter image description here

当前I'm doing

  1. 缩小图像的尺度,应用双滤波器并向上缩放回原始图像
  2. 然后将原始图像的RGB转换为灰度,然后 减少不良反应
  3. 应用自适应阈值创建edgemask
  4. 将从步骤1获得的图像与边缘遮罩与 位图 这是输出 enter image description here

然后使用OpenCV应用non-photorealistic rendering。这是最终输出enter image description here 我想生成统一颜色的脸(同时去除光反射),而不影响眼睛、嘴。如何通过调整当前代码或opencv(python)中的其他可能方法来实现这一点


Tags: 图像颜色步骤阈值rgbopencv边缘灰度
1条回答
网友
1楼 · 发布于 2024-10-01 19:14:49

{基于}

下面是一个代码,它可以满足您的需要:

import cv2
import numpy as np
from sklearn.cluster import MiniBatchKMeans

n = 32

# read image and convert to gray
img = cv2.imread('./obama.jpg',cv2.IMREAD_COLOR)
img = cv2.resize(img, (0,0), fx=.2, fy=.2)
img = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
(h, w) = img.shape[:2]

img =np.reshape(img, (img.shape[0]* img.shape[1], 3))
clt = MiniBatchKMeans(n_clusters=n)
labels = clt.fit_predict(img)
quant = clt.cluster_centers_.astype("uint8")[labels]

quant = np.reshape(quant, (h,w,3))
img = np.reshape(img, (h,w,3))

quant = cv2.cvtColor(quant, cv2.COLOR_LAB2BGR)
img = cv2.cvtColor(img, cv2.COLOR_LAB2BGR)
double = np.hstack([img, quant])
while True:
  cv2.imshow('img', double)
  k = cv2.waitKey(30) & 0xff
  if k == 27:
      break

您可以使用本教程仅将颜色量化应用于包含面的框。在

https://realpython.com/face-recognition-with-python/

相关问题 更多 >

    热门问题