python - Opencv ...获取 IPLImage 或 CvMat 中的数据

标签 python opencv iplimage

我正在用 python 中的 opencv 做一些简单的程序。我想自己编写一些算法,因此需要获取图像中的“原始”图像数据。例如,我不能只做 image[i,j],我怎样才能得到数字?

谢谢

最佳答案

使用 LoadImageM 将图像文件直接加载到 cvmat 中的快速示例:

import cv

path = 'stack.png'
mat = cv.LoadImageM(path, cv.CV_LOAD_IMAGE_UNCHANGED)
x, y = 42, 6
print type(mat)
print mat[y, x]

输出:

<type 'cv.cvmat'>
(21.0, 122.0, 254.0)

显示如何将一个或多个颜色 channel 乘以 0.5 的快速示例:

for x in xrange(mat.cols):
    for y in xrange(mat.rows):
        # multiply all 3 components by 0.5
        mat[y, x] = tuple(c*0.5 for c in mat[y, x])

        # or multiply only the red component by 0.5
        b, g, r = mat[y, x]
        mat[y, x] = (b, g, r * 0.5)

关于python - Opencv ...获取 IPLImage 或 CvMat 中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6127314/

相关文章:

python - 类型错误 : can't multiply sequence by non-int of type 'float' (python 2. 7)

java - 如何从 Java 调用 scikit-learn 分类器?

c++ - *绘制* std::vector<double> 的简单/最简单方法是什么?

opencv - 围绕轮廓对象生成颜色直方图

透明背景的javacv图像

opencv - (Opencv)在IplImage上获取轮廓

python - 如何在没有窗口的情况下将图像直接传输到屏幕?

python - 如何绘制/散点矩阵列

python - 从色相饱和度直方图检测皮肤 - OpenCV Python

image-processing - 如何将通过http post接收到的png图像加载为OpenCV IplImage格式