I was trying to convert this from C++ to Python, but it is giving different hue results.
In C++:
/// Transform it to HSV
cvtColor( src, hsv, CV_BGR2HSV );
/// Use only the Hue value
hue.create( hsv.size(), hsv.depth() );
int ch[] = { 0, 0 };
mixChannels( &hsv, 1, &hue, 1, ch, 1 );
I tried this in Python:
# Transform it to HSV
hsv = cv2.cvtColor(src, cv2.COLOR_BGR2HSV)
# Use only the Hue value
hue = np.zeros(hsv.shape, dtype=np.uint8)
ch = [0] * 2
cv2.mixChannels(hsv, hue, ch)
When you look in the documentation, you can see the C++ functions taking as arguments arrays (or vectors) of Mat
as input and output.
C++: void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts, const int* fromTo, size_t npairs)
C++: void mixChannels(const vector<Mat>& src, vector<Mat>& dst, const int* fromTo, size_t npairs)
Similarly, in Python you need to provide lists of np.array
for both source and destination.
import cv2
import numpy as np
img = cv2.imread('cage.png')
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# Baseline for comparison
h,_,_ = cv2.split(hsv)
hue = np.zeros(hsv.shape, dtype=np.uint8)
cv2.mixChannels([hsv], [hue], [0,0])
print np.array_equal(h, hue[:,:,0])
>python mix.py
True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With