numpy の ndarray 関数を同等の OpenCV C++ 呼び出しに変換して、n 次元の cv::Mat を適切なスライスに再形成/分割するのに問題があります。特に、OpenCV python2 サンプル "texture_flow.py" (>= OpenCV 2.4.3) を C++ に変換しようとしています。以下のスニペットで問題の行をマークしました。
# [......]
img = cv2.imread(fn)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# simple width and height tuple
h, w = img.shape[:2]
eigen = cv2.cornerEigenValsAndVecs(gray, 15, 3)
print eigen.shape # prints: (height, widht, 6), i.e. 6 channels
# Problem 1:
# OpenCV's reshape function is not sufficient to do this.
# probably must be split into several steps...
eigen = eigen.reshape(h, w, 3, 2) # [[e1, e2], v1, v2]
print eigen.shape # prints: (height, width, 3, 2)
# Problem 2:
# I assume this is meant to get the the v1 and v2 matrices
# from the previous reshape
flow = eigen[:,:,2]
print flow.shape # prints: (height, width, 2), i.e. 2 channels
vis = img.copy()
# C++: vis.data[i] = (uchar)((192 + (int)vis.data[i]) / 2);
vis[:] = (192 + np.uint32(vis)) / 2
d = 12
# Problem 3:
# Can probably be split into 2 nested for-loops
points = np.dstack( np.mgrid[d/2:w:d, d/2:h:d] ).reshape(-1, 2)
# [......]
問題の行を C++ に翻訳するのを手伝ってくれる人はいますか?