Questions tagged [bgr]

BGR is a way of encoding a color, parallel to RGB. For reasons of endian-ness, converting between BGR and RGB may sometimes be necessary.

BGR is a way of representing a color in a concise number of bits, similar to RGB. An RGB color is stored with Blue occupying the least significant "area" (e.g. a byte in 32-/24-bit formats), Green the second least, and Red the third least. A BGR color is represented in a similar way - the order of areas is reversed: Red occupies the least significant area, Green the second (still), and Blue the third. Thus, the difference between RGB and BGR is byte order.

However, many graphics libraries choose, as an implementation detail, to treat colors as unsigned 32-bit integers internally, with the three (or four when alpha is included) components packed into the integer. On a little-endian machine such as an x86 processor, the integer 0x01020304 will actually be stored in memory as 0x04030201, thus 0x00BBGGRR will be stored as 0xRRGGBB00.

The use of the term BGR (or BGRA) is a way for a graphics library to explain how the integer is logically ordered. This in turn means that code which directly accesses the color component bits can be made clearer and more readable, instead of expressing arbitrary access patterns.

70 questions
19
votes
3 answers

How can I know if the image is in RGB or BGR format?

Is there any way to know in advance if an image used as an input to a system is in RGB or BGR format? I am using OpenCV with java API and I would like to convert an input image into grayscale or L*a*b* color space, but in OpenCV you have to specify…
Amrmsmb
  • 1
  • 27
  • 104
  • 226
17
votes
4 answers

Converting an OpenCV BGR 8-bit Image to CIE L*a*b*

I am trying to convert a given Mat representing an RGB image with 8-bit depth to Lab using the function provided in the documentation: cvtColor(source, destination, ); I have tried the following conversion…
JT Cho
  • 263
  • 1
  • 4
  • 11
10
votes
3 answers

Is there a formula to determine overall color given BGR values? (OpenCV and C++)

I am making a function using C++ and OpenCV that will detect the color of a pixel in an image, determine what color range it is in, and replace it with a generic color. For example, green could range from dark green to light green, the program would…
Wyndrix
  • 133
  • 2
  • 10
8
votes
2 answers

python - opencv - convert pixel from bgr to hsv

img = cv2.imread('example.jpg') img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) # lower mask (0-10) lower_red = np.array([0, 50, 50]) upper_red = np.array([10, 255, 255] mask0 = cv2.inRange(img_hsv, lower_red, upper_red) # upper mask…
cmplx96
  • 1,541
  • 8
  • 34
  • 48
8
votes
2 answers

Convert CMSampleBufferRef to UIImage with YUV color space?

I'm working with AVCaptureVideoDataOutput and want to convert CMSampleBufferRef to UIImage. Many answers are the same, like this UIImage created from CMSampleBufferRef not displayed in UIImageView? and AVCaptureSession with multiple previews It…
onmyway133
  • 45,645
  • 31
  • 257
  • 263
6
votes
0 answers

What is correct pixel format in ImageWatch for YV12 and NV12?

There is a nice Visual Studio extension Image Watch. It can take an arbitrary address in RAM and show its contents as an image with @mem operator. @mem(address, type, channels, width, height, stride): interpret raw memory as pixels, starting at…
wl2776
  • 4,099
  • 4
  • 35
  • 77
5
votes
1 answer

cv2.cvtcolor bgr2gray seems get an error image

# the code is as follows, implemented, but the result is possibly wrong, it is not the grayscale i wanted, someone gonna help me with that, it's seems quite simple, but i just don't know what wrong import cv2 import matplotlib.pyplot as plt …
King Excel
  • 51
  • 1
  • 1
  • 2
5
votes
2 answers

winapi - CreateDIBitmap in 24bpp is in BGR not RGB

I am trying to create an HBITMAP from an array which will contain the color values for the Pixels. The thing is when I try to create a 24-bpp Bitmap, the CreateDIBItmap is using BGR values instead of RGB as I would like. The code to create the…
Jean Claude Abela
  • 782
  • 1
  • 9
  • 26
3
votes
1 answer

Conversion from BGR to YUYV with OpenCV Python

I have been trying to convert a BGR captured frame into the YUYV format. In OpenCV Python I can do convert YUYV into BGR with COLOR_YUV2BGR_YUY2 conversion code but I cannot do the reverse of this operation (there is no conversion code for this…
Can Berk
  • 33
  • 6
3
votes
2 answers

Reading the BGR colors from a bitmap in C

I was trying to obtain the RGB values from a 24-bit BMP file. The image that I am using is a tiny image, all red, so all pixels BGR configuration should be B:0 G:0 R:255. I do this: int main(int argc, char **argv) { principal(); return…
Mariano
  • 31
  • 1
  • 2
3
votes
1 answer

HSV image in openCV for color recognition

I have the following BGR image (a car's front), I want to recognize its color I converted it to HSV (I know imshow() doesn't understand the HSV and will print it as BGR) 1: Now, I want to get the hue value and know in which range it lies to…
Maram
  • 37
  • 1
  • 1
  • 6
3
votes
2 answers

BGR Histogram comparison using EmguCV

I´m trying to make some kind of image ranking depending on histogram similarities. I take an image, and need to compare its histogram with a database of images ordering them depending in how similar are to the source image. This should work like a…
Evans
  • 1,589
  • 1
  • 14
  • 25
2
votes
3 answers

OpenNI RGB image to OpenCV BGR IplImage conversion?

The image which one can get from OpenNI Image Meta Data is arranged as an RGB image. I would like to convert it to OpenCV IplImage which by default assumes the data to be stored as BGR. I use the following code: XnUInt8 * pImage = new XnUInt8…
Rasoul
  • 3,758
  • 5
  • 26
  • 34
2
votes
1 answer

Slicing the channels of image and storing the channels into numpy array(same size as image). Plotting the numpy array not giving the original image

I separated the 3 channels of an colour image. I created a new NumPy array of the same size as the image, and stored the 3 channels of the image into 3 slices of the 3D NumPy array. After plotting the NumPy array, the plotted image is not same as…
2
votes
2 answers

what is the error : "ValueError: assignment destination is read-only"?

When I am opening a jpg file using cv2.imread() and it fails sometimes which is likely due to BGR format I used. So I switched to PLT to use RGB. import matplotlib.pyplot as plt import numpy as np def rgb_to_gray(img): grayImage =…
PCG
  • 2,049
  • 5
  • 24
  • 42
1
2 3 4 5