Ask Your Question

shxuy's profile - activity

2019-04-11 00:19:49 -0600 commented answer Why is the order of color channels in funtion copyMakeBorder in Python version not (b, g, r) but (r, g, b)?

Thanks. But it seems that we have to modify many lines of the code which is too complicated for me and I am not able to

2019-04-11 00:17:01 -0600 marked best answer Why is the order of color channels in funtion copyMakeBorder in Python version not (b, g, r) but (r, g, b)?

As we all know, OpenCV uses a differnt order of color channels (b, r, g,) not (r, b, g) for a historical reason. But I find that in python version, the second parameter of cv.copyMakeBorder, namely 'value', uses (r, b, g) as its order of color channels, which is inconsistent with other APIs and confused me.

So maybe there is a typo or a tiny mistake in the tutorial for Python tutorial_py_basic_ops. The tutorial provides a code snippet as shown below to teach the usage of funtion cv.copyMakeBorder.

import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
BLUE = [255,0,0]
img1 = cv.imread('opencv-logo.png')
replicate = cv.copyMakeBorder(img1,10,10,10,10,cv.BORDER_REPLICATE)
reflect = cv.copyMakeBorder(img1,10,10,10,10,cv.BORDER_REFLECT)
reflect101 = cv.copyMakeBorder(img1,10,10,10,10,cv.BORDER_REFLECT_101)
wrap = cv.copyMakeBorder(img1,10,10,10,10,cv.BORDER_WRAP)
constant= cv.copyMakeBorder(img1,10,10,10,10,cv.BORDER_CONSTANT,value=BLUE)
plt.subplot(231),plt.imshow(img1,'gray'),plt.title('ORIGINAL')
plt.subplot(232),plt.imshow(replicate,'gray'),plt.title('REPLICATE')
plt.subplot(233),plt.imshow(reflect,'gray'),plt.title('REFLECT')
plt.subplot(234),plt.imshow(reflect101,'gray'),plt.title('REFLECT_101')
plt.subplot(235),plt.imshow(wrap,'gray'),plt.title('WRAP')
plt.subplot(236),plt.imshow(constant,'gray'),plt.title('CONSTANT')
plt.show()

The author names a variable called 'BLUE' and assigns [255, 0, 0] to it which is sensible in the first glance. Then the variable 'BLUE' is used in

constant= cv.copyMakeBorder(img1,10,10,10,10,cv.BORDER_CONSTANT,value=BLUE)

in order to add a pure blue border to img1.

However, we get a pure red border at last which titled 'CONSTANT' in the bottom-right corner of the whole final result picture.

the result

So may I fork the github repository and replace the variable name 'BLUE' with 'RED' to keep semantic consistency of the tutorial?

2019-04-11 00:17:01 -0600 received badge  Scholar (source)
2019-04-10 01:42:59 -0600 asked a question Why is the order of color channels in funtion copyMakeBorder in Python version not (b, g, r) but (r, g, b)?

Why is the order of color channels in funtion copyMakeBorder in Python version not (b, g, r) but (r, g, b)? As we all kn