https://www.learnopencv.com/why-does-opencv-use-bgr-color-format/

原因其实很简单啊,这个解释非常的风趣,“古罗马的马屁股”。

One of the elements of good design is the principle of least astonishment ( a.k.a principle of least surprise). A good intuitive design makes the user not think.
When you see a handle on a door, you want to pull it. When you see a door with a metal plate, you want to push it. Those are the expectations of a user of the door and when the designer of a door respects these expectations, a user can use the door without exerting any mental energy. But if the design is inconsistent with a user’s expectation, a simple act of opening a door can become a mental burden.
OpenCV is a very useful library, but when it comes to the principle of least surprise, it is an unqualified disaster. When I am writing Computer Vision code in MATLAB, I rarely refer to the documentation. While working with OpenCV, I have the docs permanently open in a browser tab.
OpenCV seems to have been built with the principle of maximum surprise in mind! And it all begins with the default BGR pixel format. It does not play well with libraries that use the standard RGB pixel format. E.g. when you try to display an image using matplotlib after reading it using imread in OpenCV, the result looks funny.
“Why not use RGB when everybody else and their aunts use RGB?”
This is the question I asked Dr. Gary Bradski, founder of OpenCV, when I met him at a conference a few months back, although I left out the part about everybody and their aunts using RGB. He answered my question with another question.
“Why is the the US standard railroad gauge 4 feet, 8.5 inches?”
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.
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.

Now the twist to the story . . .
There’s an interesting extension to the story about railroad gauges and horses’ behinds. When we see a Space Shuttle sitting on its launch pad, there are two big booster rockets attached to the sides of the main fuel tank. These are solid rocket boosters, or SRBs. The SRBs are made by Thiokol at their factory in Utah. The engineers who designed the SRBs might have preferred to make them a bit fatter, but the SRBs had to be shipped by train from the factory to the launch site. The railroad line from the factory had to run through a tunnel in the mountains. The SRBs had to fit through that tunnel. The tunnel is slightly wider than the railroad track, and the railroad track is about as wide as two horses’ behinds.
So, the major design feature of what is arguably the world’s most advanced transportation system was determined over two thousand years ago by the width of a Horse’s Ass!
Why did they choose BGR color space in OpenCV ?
The reason the early developers at OpenCV chose BGR color format is that back then BGR color format was popular among camera manufacturers and software providers. E.g. in Windows, when specifying color value using COLORREF they use the BGR format 0x00bbggrr.
BGR was a choice made for historical reasons and now we have to live with it. In other words, BGR is the horse’s ass in OpenCV.

为什么opencv使用BGR 格式,而不是RGB格式?相关推荐

  1. 使用C++实现YUV格式图像与RGB格式图像之间相互转换

    使用C++实现YUV格式图像与RGB格式图像之间相互转换 一.RGB与YUV转换公式 1.RGB转YUV 1)RGB转换亮度与色差信号公试: 2)归一化为YUV的转化公试为: 2.YUV转RGB 二. ...

  2. YUV格式文件转RGB格式

    网上已知YUV转RGB公式为: R = Y + 1.4075 *(V-128) G = Y – 0.3455 *(U –128) – 0.7169 *(V –128) B = Y + 1.779 *( ...

  3. 【DSP开发】【VS开发】YUV与RGB格式转换

    [视频处理]YUV与RGB格式转换 YUV格式具有亮度信息和色彩信息分离的特点,但大多数图像处理操作都是基于RGB格式. 因此当要对图像进行后期处理显示时,需要把YUV格式转换成RGB格式. RGB与 ...

  4. 随机颜色十六进制(#ffffff)或rgb格式

    // 定义一个随机颜色的函数 function getRandomColor(flag = true) { // 如果是true就传递 #ffffff格式,否则传rgb格式 if (flag) { l ...

  5. python使用openCV加载图像、并将BGR格式转换成HSV格式、定义HSV格式中需要分离颜色的掩码(掩模)区间(mask)、并使用mask信息进行颜色分离、BGR格式的图像转化为RGB、并可视化

    python使用openCV加载图像.并将BGR格式转换成HSV格式.定义HSV格式中需要分离颜色的掩码(掩模)区间(mask).并使用mask信息进行颜色分离.将BGR格式的图像转化为RGB.可视化 ...

  6. OpenCV读出来的是按BGR存储的,如何转变成传统的RGB格式

    opencv 视频帧的数据是按按BGR存储的,想转变成传统的RGB格式便于和其他库对接使用 方法1 核心代码 cv2.cvtColor(Frame,cv2.COLOR_BGR2RGB) ,其中 Fra ...

  7. 在Python中使用OpenCV将RGB格式的图像转换为HSV格式的图像

    An HSV is another type of color space in which H stands for Hue, S stands for Saturation and V stand ...

  8. python–颜色英文与RGB格式互转

    python–颜色英文与RGB格式互转 使用pip安装webcolors pip install webcolors 1- 导入webcolors import webcolors 2-英文转RGB ...

  9. YUV / RGB 格式及快速转换

    YUV是指亮度参量和色度参量分开表示的像素格式,而这样分开的好处就是不但可以避免相互干扰,还可以降低色度的采样率而不会对图像质量影响太大. YUV是一个比较笼统地说法,针对它的具体排列方式,可以分为很 ...

最新文章

  1. POJ 2114 - Boatherds
  2. java中字符串的精确匹配_Java最佳实践–字符串性能和精确字符串匹配
  3. matlab界area_Matlab的数据科学界
  4. 本地计算机用plsql访问虚拟机中的oracle数据库
  5. [C++] - C++11 多线程 - Condition Variable
  6. mongodb查询的语法(大于,小于,大于或等于,小于或等于等等)
  7. 计算机与管理科学的交叉与融合,计算机信息管理学科交叉融合研究论文
  8. Atitit 单片机与嵌入式系统原理与概念 目录 1. 寄存器、数据库,堆栈 2 1.1. 寻址模式 2 1.2. 指令 2 1.3. Watchdog 中断 2 2. 软件是如何影响硬件设计的 2
  9. Object-C语法
  10. 解析Power Apps 自动生成的App - 1
  11. 海思16DV300 移动侦测
  12. 各类学科入门书籍推荐
  13. Git使用学习(十四、解决分支合并后产生的冲突)
  14. 品牌如何正确联动B站UP主“恰饭视频”,最近一支不像恰饭视频的作品在B站火了
  15. hbiuder运行php_hbuilderx中运行php图文说明
  16. 上海 政府性 常用网站
  17. 滴滴裁员2000人,员工竟然被裁出幸福感,获得员工的一致好评?
  18. PM如何写好产品需求文档
  19. bind9 dlz mysql_源码安装Bind 9.10 正式版 开启DLZ数据库支持 和 数据库view查询
  20. 手机日常使用技巧、和手机停机如何免费上网 。好多大家不知道的功能:不看后悔哦

热门文章

  1. 微信如何定时发送朋友圈?
  2. 《数据处理与知识发现》章节测验复习
  3. STM32F407野火霸天虎系列笔记(三)UART通信
  4. 基于深度学习的二维码检测和识别(含完整代码和数据)
  5. Shell:环境变量
  6. 站长链接php提交实例,百度站长平台链接提交
  7. 机器人工厂参观心得_机器人工厂的建立
  8. 小波变换与图像图形处理技术_产品图形:使图像更具信息性的6种技术
  9. java毕业设计基地信息可视化(附源码、数据库)
  10. 对 PO、BO、DTO、VO 的理解