对于 numpy 中的 RGB 图像,cv::MatIterator 的等价物是什么?我读过,numpy.nditer
但我无法准确地使用它来制定我的要求。
例如,考虑以下使用 OpenCV 迭代每个像素并分配 RGB 值的 C++ 代码:
cv::Mat rgbImage(someheight, somewidth, CV_8UC3);
cv::MatIterator_<cv::Vec3b> first = rgbImage.begin<cv::Vec3b>()
cv::MatIterator_<cv::Vec3b> last = rgbImage.end<cv::Vec3b>()
while (first!=last){
*first = (get <cv::Vec3b> value from somewhere)
++first;
}
在上面的代码中,MatIteratorfirst
用于直接在图像中的每个像素处分配 cv::Vec3b 类型的 (R,G,B) 值。
考虑到下面的 Python 代码,
rgbImage = np.zeros((someheight, somewidth, 3), dtype = np.uint8)
first= np.nditer(rgbImage)
while not first.finished():
???
有人可以提供一个示例,说明直接分配 (R,G,B) 值的元组的等效 numpy 版本可能是什么样的?谢谢!