Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想制作一个变量矩阵以从 python 中的图片中获取值,我一直在搜索,我在 C++ 中得到了这段代码:
Mat src, dst; // Load an image src = imread("book.png", CV_LOAD_IMAGE_GRAYSCALE);
然后我也想知道如何unsigned char在python中制作,在c ++中是这样的:
unsigned char
dst.at<uchar>(y,x) = 0.0;
谁能帮我?
该 C++ 代码使用 OpenCV 库,为了获得相同的结果(您必须首先安装 Numpy 和 OpenCV Python 包装器),您只需要执行以下操作:
import cv2 src = cv2.imread('book.png', cv2.CV_LOAD_IMAGE_GRAYSCALE)
这将生成一个numpy.ndarray调用src,其值将是无符号整数(即它们在 [0,255] 区间内取值)
numpy.ndarray
src