2016年12月12日 星期一

Opencv 印出圖片像素

訪問每個像素,還不知道原理。
了解後再補上

code

xx.cpp 



#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;

int main(int argc, char** argv){
int c = 0;
int width=src->width;//图片宽度
int height = src->height;//图片高度

for (size_t row=0;row<height;row++){
uchar* ptr = (uchar*)src->imageData+row*src->width;//获得灰度值数据指针
for (size_t cols=0;cols<width;cols++){
int intensity=ptr[cols];
cout<<" "<<intensity<<" ";
c++;
}
cout<<"\n"<<endl;
}
cout<<("c = %d",c)<<endl;
cvSave("1R.jpg",src); //使用cvSave將數值轉換,使用記事本打開可直接看pixel的灰階值(0~255)
return 0;
}

編譯
 g++ 01_inage_to_gray.cpp -o  01_inage_to_gray `pkg-config --cflags --libs opencv`

Reference:

https://zhidao.baidu.com/question/412847971.html

沒有留言:

張貼留言