And*_*olo 2 python opencv computer-vision
我\xe2\x80\x99m尝试使用opencv在1080p相机上拍照,但是,只希望照片为224x224像素。我怎样才能使用 opencv 来做到这一点。
\n\n我目前有以下代码:
\n\nImport cv2\nCap = cv2.VideoCam(0)\nCap.set(3, 224)\nCap.set(4, 224)\n\nRet, frame = cap.read()\nRun Code Online (Sandbox Code Playgroud)\n\n然而,当我查看框架的形状时,它不是(224, 224, 3)。有人可以帮我弄清楚如何让它输出我想要的像素尺寸
\n当您说您想要 224x224 图像时,这取决于您的意思。如果我们从这张 1920x1080 的图像开始,您可能需要:
因此,假设您已将相机中的帧读取到一个名为的变量中,im如下所示:
...
...
ret, im = cap.read()
Run Code Online (Sandbox Code Playgroud)
如果您想要 (A),请使用:
# If you want the top-left corner
good = im[:224, :224]
Run Code Online (Sandbox Code Playgroud)
如果您想要 (B),请使用:
# If you want the centre
x = h//2 - 112
y = w//2 - 112
good = im[x:x+224, y:y+224]
Run Code Online (Sandbox Code Playgroud)
如果您想要 (C),请使用:
# If you want the largest square, scaled down to 224x224
y = (w-h)//2
good = im[:, y:y+h]
good = cv2.resize(good,(224,224))
Run Code Online (Sandbox Code Playgroud)
如果您想要 (D),请使用:
# If you want the entire frame distorted to fit 224x224
good = cv2.resize(im,(224,224))
Run Code Online (Sandbox Code Playgroud)
关键词:图像处理、视频、1920x1080、1080p、裁剪、扭曲、最大正方形、中心部分。左上角,Python,OpenCV,框架,提取。
| 归档时间: |
|
| 查看次数: |
1276 次 |
| 最近记录: |