- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个比图像小 4 倍的网格,我想用来自网格的信息扭曲图像,但是,当使用 cv2.remap 时,它会使扭曲像素化(见下图)。我怎样才能使失真更平滑?
原文:
期望的输出:
我的输出:
我的代码:
img = np.array(Image.open('astronaut.jpg')) # Shape -> (512, 512, 3)
mesh = Mesh('astronaut.msh').get_uvs() # Shape -> (128, 128, 2), 2 channels for x and y
new_mesh = np.zeros((img.shape[1], img.shape[0], 2))
new_mesh[:,:,0] = np.repeat(np.repeat(mesh[:,:,0], 4, axis=0), 4, axis=1)
new_mesh[:,:,1] = np.repeat(np.repeat(mesh[:,:,1], 4, axis=0), 4, axis=1)
nh, nw = img.shape[:2]
xs, ys = np.meshgrid(np.arange(0, nw), np.arange(0, nh))
xs = xs + new_mesh[:,:,0] * 4 # multiply by constant to modulate distort strength
ys = ys + new_mesh[:,:,1] * 4
xs = np.float32(xs)
ys = np.float32(ys)
dst= cv2.remap(img.astype(np.uint8), xs, ys, cv2.INTER_CUBIC)
最佳答案
OpenCV 不是罪魁祸首。它完全按照您的指示执行。
这些人工制品来自您对 np.repeat
的使用。这只是重复 map 数组中的每个索引元素。您没有正确地对网格进行上采样,您实际上只是使用该代码复制 4x4 补丁。
适本地对你的网格进行上采样(np.repeat
是错误的),然后你会得到很好的结果。您可以使用 cv.resize
和除了最近邻插值之外的任何东西轻松做到这一点。如果您需要精确控制边界行为,您将需要 warpAffine 和自定义转换矩阵。您甚至可以使用 cv.pyrUp
(两次)。
当您展示 MRE 时(网格的一些数据),我会用工作代码更新我的答案。
关于来自网格的 Python cv2.remap 创建像素化失真,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73367759/
我有一堆不同大小的(灰度)图像,我调整它们的大小以确保一个维度相同并填充另一个维度(a la this answer)。然而,我在第 4 行(第二到下面代码的最后一行)。我将如何解决这个问题? 我尝试
现在我有了图像 A,我想将它重新映射到与图像 A 大小不同的图像 B。 对于每个像素坐标 (x, y),它在图像 B 上具有坐标 (r, theta)。 谁能告诉我如何实现它,最好有示例代码?因为我不
我得到了一个非常简单的二进制掩码。 1 = Sunday 2 = Saturday 4 = Friday 8 = Thursday 16 = Wednesday 32 = Tuesday 64 = M
我正在试用 userns-remap Docker 在容器内创建文件的功能 root用户并拥有此文件的所有者为 test主机上的用户。 我已将以下内容添加到 /etc/docker/daemon.js
cv::remap(imageA, dst1, map_x, map_y, cv::INTER_LINEAR,
我有一个紧密的循环,我在其中获取相机图像,对其进行去畸变,然后根据某种变换(例如透视变换)对其进行变换。我已经想出为每个操作使用 cv::remap(...),这已经比使用普通矩阵操作更有效。 以我的
我目前正在为一对立体相机编写 openCV 程序。完成相机校准和立体校准。 下一步是从我获得的 2 张图像中找到特征在空间中的位置。这就是为什么我必须对图像进行立体校正并在之后进行计算的原因。 我在
在 docker 中,在容器内创建的文件在从主机检查它们时往往具有不可预测的所有权。默认情况下,卷上文件的所有者是 root (uid 0),但是一旦非 root 用户帐户参与到容器中并写入文件系统,
我有一个比图像小 4 倍的网格,我想用来自网格的信息扭曲图像,但是,当使用 cv2.remap 时,它会使扭曲像素化(见下图)。我怎样才能使失真更平滑? 原文: 期望的输出: 我的输出: 我的代码:
我有一个键盘,在空格键旁边有一个神秘的 LNG 键,AltGr 通常位于该位置。有没有办法让AltGr(Alt)出来? 这是 LNG 键被按下并释放一次的 xev 控制台输出: KeyPress ev
我正在使用“dup”克隆一个事件记录模型(称为项目)。它有几个协会;一个项目有很多步骤,步骤有很多图片和视频等。 我发现当我克隆一个项目时,它会成功地创建该项目的相应步骤、图像和视频的克隆。但是,图像
(Mac)是否可以重新映射大写锁定以执行除操作系统预期用途以外的任何其他操作?我曾尝试在Karabiner和“系统偏好设置”>“键盘”>“修改键”中使用它,但是没有运气。这并不是使它成为修饰键,而只是
这是我应该问的问题,而不是这个: Emacs evil: space as a prefix key in motion state 我想定义一堆用于移动、移动、打开和关闭窗口和缓冲区的命令,这些命令
我正在尝试为我的 Aurelia(+ webpack + TypeScript)网站设置单元测试。我的 karma.conf.js 如下所示(类似于 aurelia-navigation 骨架中所做的
我遇到了以下简单代码的段错误: #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #inclu
我把答案里的代码拿走了https://stackoverflow.com/a/10374811/4828720来自 Image transformation in OpenCV并尝试使它适应我的形象。
我有一个 11 x 11 顶点的网格。这个想法是每个点(顶点)都保存变形图像中该像素的归一化浮点位置。例如。如果我想拉伸(stretch)左上边缘,我写在第一个顶点 (-0.1, -0.1)。 我有网
运行后cat -t ,我测试了以下情况: ctrl + tab只加了一个tab空间 ctrl + /添加 ^_ ctrl + `添加 ^@ ctrl + shift + backspace向左删除(与
在this article Jeroen 解释了一个使用 XML 文件将 Java Bean getter 和 setter 重新映射到 .NET 属性的示例。 如果我想将名为 showDialog(
我想为插入模式下的导航映射以下内容: # 向左移动 # 向下移动 # 向上移动 # 向右移动 因此,我将以下内容添加到我的 .vimrc 中: inoremap inoremap in
我是一名优秀的程序员,十分优秀!