opencv - 在opencv中读写图像

在OpenCV中,我想加载图像并获取像素值。将输入图像像素分配给另一个数组。该数组值将被重构并显示输出图像。如果我对输入像素进行了一些操作,我想得到相应像素的输出。用于此的命令是什么?

最佳答案

嗨,我会做以下

#include "cv.h"
#include "highgui.h"
#include <stdio.h>

IplImage *image=0, *image2=0;

int main(int argc, char** argv) {
    char* file, *outF;
    //Usage: filename.exe imagefile outputimage
    if (argc == 3) {
        file=argv[1];
        outF=argv[2];
    }else {
        exit(0);
    }
    //Loading file
    if( (image = cvLoadImage( file, 1)) == 0 )
        return -1;
    // creating image in greyscale
    image2 = cvCreateImage(cvSize(image->width,image->height),IPL_DEPTH_8U,1);
    myFunction();
}

void myFunction() {
    uchar *pix; // To store pixel value temporarily
    uchar *out; 
    //// NOW U CAN ACCESS EACH Pixel
    for ( int posY=0; posY<image->height;posY++) {
        for ( int posX=0; posX<image->width;posX++) {
            pix=&((uchar *)(image->imageData+posY*image->widthStep))[posX]; //this is to get value
            out=&((uchar *)(image2->imageData+posY*image2->widthStep))[posX];

             //Do your stuff here ---Example
             // to access original image file use
             // uchar c = *pix;

             // this assgins your output image your manipulations
             *out= someValue[x][y]; //(0-255) your assignment from your array, It should work
            //----------------------


        }
    }
}

您还需要保存一些其他内容,并查看图像cvSaveImage(outF,image2) cvNamedWindow(file,1) cvShowImage(file,image)。有关here的更多信息。

https://stackoverflow.com/questions/6757274/

相关文章:

docker - 为什么 Neo4J docker 身份验证不起作用

memory - cvShowImage和Kinect SDK的内存问题:骨架查看器

opencv - 检测视频帧中的现实世界对象

image - 将 GDIPlus::Bitmap 转换为 cv::Mat(OpenCV C++ 接

opencv - cvSetErrMode 不工作

c# - EmguCV - 运动检测不返回角度

opencv - 什么最适合您的视频跟踪?为什么?

opencv - 保存IPL_DEPTH_IMAGE供以后处理

image - 从输入图像获取RGB像素并在opencv中重建输出图像

visual-studio-2010 - 我无法使用 VS2010 运行 openCV2.3.1