大家好,我想使用OpenCV来获取黑白图像的像素值,使输出结果如下:
10001
00040
11110
00100
这是我当前的代码,但我不确定如何访问CV_GET_CURRENT
调用的结果。 有人能提供帮助吗?
IplImage readpix(IplImage* m_image) {
cout << "Image width : " << m_image->width << "\n";
cout << "Image height : " << m_image->height << "\n";
cout << "-----------------------------------------\n";
CvPixelPosition8u position;
CV_INIT_PIXEL_POS(position, (unsigned char*)(m_image->imageData), m_image->widthStep, cvSize(m_image->width, m_image->height), 0, 0, m_image->origin);
for(int y = 0; y < m_image->height; ++y) // FOR EACH ROW
{
for(int x = 0; x < m_image->width; ++x) // FOR EACH COL
{
CV_MOVE_TO(position, x, y, 1);
unsigned char colour = *CV_GET_CURRENT(position, 1);
// I want print 1 for a black pixel or 0 for a white pixel
// so i want goes here
}
cout << " \n"; //END OF ROW
}
}