作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
例如,当我运行此命令时:
import cv2
import numpy as np
from collections import Counter
# load image, calculate some basic stats
path = 'path/to/my/image.png'
bgr_img = cv2.imread(path)
h, w, c = bgr_img.shape
print("There are %d entries in this %d channel image" % (h*w*c, c))
# convert and then invert, we should get the same image
bgr_img2 = cv2.cvtColor(cv2.cvtColor(bgr_img, cv2.COLOR_BGR2HSV), cv2.COLOR_HSV2BGR)
print("all entries match: %s" % np.all(bgr_img == bgr_img2))
# hmm, we don't. let's see where the differences are
mismatches = np.where(bgr_img != bgr_img2)
print("there are %d mismatched entries" % len(mismatches[0]))
print("mismatches are along the following channels: %s" % Counter(mismatches[2]))
# ok, clearly lots of them. maybe they're all just off by 1 or 2?
mm = zip(mismatches[0], mismatches[1], mismatches[2])
differences = []
for x, y, c in mm:
diff = bgr_img[x, y, c] - bgr_img2[x, y, c]
differences.append(diff)
print(differences)
There are 1228800 entries in this 3 channel image
all entries match: False
there are 524511 mismatched entries
mismatches are along the following channels: Counter({1: 270572, 0: 253939})
[1, 1, 1, 254, 1, 254, 1, 3, 1, 3, 1, 3, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 1, 3, 1, 3, 1, 3, 1, 254, 1, 254, 254, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, ...]
最佳答案
您应该获得几乎相同的图像,但除了边缘情况外,不会获得相同的位。从BGR到HSV(以及向后)涉及到空间之间的转换,这些空间对于其他空间中的所有值没有相同的表示形式。小数舍入误差会逐渐增加。
请参阅https://docs.opencv.org/3.4/df/d9d/tutorial_py_colorspaces.html中有关色调范围为[0,179]的注释。如果您考虑一下,这意味着从BGR(或RGB)转换时会丢失信息。您无法可靠地收回这些位。
关于python - OpenCv反转:将BGR转换为HSV,然后再返回BGR-我是否应该获得相同的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52141240/
我有本地更改和远程更改。 有人告诉我必须先推,再 pull 。这背后有什么原因吗? 最佳答案 那个人错了:正确的模型是pull-before-you-push,而不是相反。 当您pull时,git 将
我正在使用最新版本的 Flat UI Pro 1.3.2 ( http://designmodo.com/flat/ ),jQuery 插件 flatui-radiocheck v0.1.0 和 iO
我是一名优秀的程序员,十分优秀!