起始数据:包含2d数组(620x480)的图像(显示人脸)和包含眼睛图像的2d数组(30x20)。面部图像包括眼睛图像。
如何将眼睛图像扩展到36x60以包含面部图像中的像素?有现成的解决方案吗?
另一个类似的任务:眼睛图像的尺寸为37x27。我如何将眼睛图像扩展到目标(最接近36x60)大小,例如39x65,即在调整大小之前保持所需的宽高比,然后再调整为36x60。
测试代码(可通过参考获得项目):
import dlib
import cv2 as cv
from imutils.face_utils import shape_to_np
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor('res/model.dat')
frame = cv.imread('photo.jpg')
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
img = frame.copy()
dets = detector(gray, 0)
for i, det in enumerate(dets):
shape = shape_to_np(predictor(gray, det))
shape_left_eye = shape[36:42]
x, y, h, w = cv.boundingRect(shape_left_eye)
cv.rectangle(img, (x, y), (x + h, y + w), (0, 255, 0), 1)
cv.imwrite('file.png', frame[y: y+w, x: x+h])
Run Code Online (Sandbox Code Playgroud)
我正在尝试运行 OpenAI-gym 官方文档中提供的基本 OpenAI-gym 程序:
import gym
env = gym.make("CartPole-v1")
observation = env.reset()
for _ in range(1000):
env.render()
action = env.action_space.sample() # your agent here (this takes random actions)
observation, reward, done, info = env.step(action)
if done:
observation = env.reset()
env.close()
Run Code Online (Sandbox Code Playgroud)
但程序输出如下错误:
AttributeError: module 'gym' has no attribute 'make'。
我正在使用 opencv 对图像进行图像处理。
我只想将图像转换为黑白,但我想删除一些灰色(噪点)
这是我的图片:

我想要一张白色和黑色的图像,只是为了清楚地显示文本:
“ 参与 -3.93 C Redevance Patronale -1.92 C ”
我尝试用 OpenCV 更改图像的阈值但没有成功
#grayscale
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
#binary
ret,thresh = cv2.threshold(gray,175,255,cv2.THRESH_BINARY_INV)
Run Code Online (Sandbox Code Playgroud)