01. OpenCV为什么使用BGR颜色模式?

优秀设计的要素之一是最少意外原则(又名最少意外原则)。一个好的直观设计可以让用户无需思考就能知道如何使用它。
当你看到门上的把手时,你想拉它。当你看到一扇有金属板的门时,你想推它。这些都是门的使用者的期望,当门的设计师尊重这些期望时,用户可以使用门而不需要施加任何精神能量。但如果设计与用户的期望不一致,那么一个简单的开门动作就会成为一种精神负担。

OpenCV是一个非常有用的库,但是当涉及到最小意外原则时,它是一个不折不扣的灾难。当我在MATLAB中编写计算机视觉代码时,我很少参考文档。在使用OpenCV时,我将文档永久地打开在浏览器选项卡中。

OpenCV似乎是用最大惊喜的原则来构建的!这一切都始于默认的BGR像素格式。它不能很好地与使用标准RGB像素格式的库配合使用。例如,当您在OpenCV中使用imread读取图像后尝试使用matplotlib显示图像时,结果看起来很可笑。

“其他人以及他们的亲戚都在用RGB,为什么OpenCV不用呢?”
这是我在几个月前的一次会议上遇到OpenCV的创始人Gary Bradski博士时问他的问题,尽管我省略了关于每个人和他们的亲戚使用RGB的部分。他用另一个问题回答了我的问题。“为什么美国铁路的标准轨距是4英尺8.5英寸?”

The answer to that question of course is “Because of Roman horse’s ass!”

For people who do not know this not-so-true story, I have copied the following from snopes

The US standard railroad gauge (width between the two rails) is 4 feet, 8.5 inches. That’s an exceedingly odd number. Why was that gauge used?
Because that’s the way they built them in England, and the US railroads were built by English expatriates.

这个问题的答案当然是“因为罗马马的屁股!”
对于那些不知道这个不太真实的故事的人,我从snopes上复制了以下内容:美国标准铁路轨距(两轨之间的宽度)是4英尺8.5英寸。这是一个非常奇怪的数字。为什么要用那个量规?因为这是他们在英国建造铁路的方式,而美国的铁路是由英国侨民建造的。

Why did the English build them like that? Because the first rail lines were built by the same people who built the pre-railroad tramways, and that’s the gauge they used.

Why did “they” use that gauge then? Because the people who built the tramways used the same jigs and tools that they used for building wagons which used that wheel spacing.
为什么英国人要把它们造成那样?因为第一条铁路线是由建造铁路之前的有轨电车的人建造的,他们使用的是这种轨距。那“他们”为什么要用那个量规呢?因为建造有轨电车的人使用的夹具和工具和建造马车的工具是一样的。

Okay! Why did the wagons have that particular odd wheel spacing? Well, if they tried to use any other spacing, the wagon wheels would break on some of the old, long distance roads in England, because that’s the spacing of the wheel ruts.
好吧!为什么马车的车轮间距这么奇怪?好吧,如果他们试图使用其他的间距,马车的轮子就会在英国的一些古老的长途道路上断裂,因为那是车轮的车辙间距。

So who built those old rutted roads? The first long distance roads in Europe (and England) were built by Imperial Rome for their legions. The roads have been used ever since. And the ruts in the roads? Roman war chariots first formed the initial ruts, which everyone else had to match for fear of destroying their wagon wheels. Since the chariots were made for (or by) Imperial Rome, they were all alike in the matter of wheel spacing.
那么是谁修的那些车辙路呢?欧洲(和英国)的第一条长途公路是罗马帝国为他们的军团修建的。从那以后,这条路一直在使用。路上的车辙呢?罗马战车首先形成了最初的车辙,其他所有人都必须与之匹配,以免损坏他们的马车车轮。由于战车是为(或由)罗马帝国制造的,它们在车轮间距方面都是相似的。

The United States standard railroad gauge of 4 feet, 8.5 inches derives from the original specification for an Imperial Roman war chariot. Specifications and bureaucracies live forever. So the next time you are handed a specification and wonder what horse’s ass came up with it, you may be exactly right, because the Imperial Roman war chariots were made just wide enough to accommodate the back ends of two war horses. Thus, we have the answer to the original question.
美国标准铁路轨距为4英尺8.5英寸,源自罗马帝国战争战车的原始规格。规范和官僚主义永远存在。所以,下次当你拿到一份规格书,想知道是哪匹马的屁股做出来的时候,你可能完全正确,因为罗马帝国战车的宽度刚好能容纳两匹战马的屁股。这样,我们就有了原来问题的答案。

回到原始问题,为什么OpenCV使用BGR颜色空间呢?

OpenCV的早期开发人员选择BGR颜色格式的原因:是当时BGR颜色格式在相机制造商和软件提供商中很流行。例如,在Windows中,当使用COLORREF指定颜色值时,他们使用BGR格式0x00bbggrr。
BGR是出于历史原因做出的选择,现在我们必须接受它。换句话说,BGR是OpenCV中的翘臀。

  • 19
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值