我有一个 IplImage
,我想使用以下代码对其进行二值化(不使用 cvThreshold
函数):
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
static IplImage* img ;
img = cvLoadImage ("c:\\Mytest.jpg");
for(int i=0;i<img->height;i++)
{
for(int j=0;j<img->width;j++)
{
if (img->imageData[i*img->widthStep+j]<=10)
((uchar *)img->imageData)[i*img->widthStep+j]=255;
else
((uchar *)img->imageData)[i*img->widthStep+j]=0;
}
}
cvShowImage("After",img);
waitKey(0);
};
但是这段代码只影响了图像的一部分,像这样:
最佳答案
看,使用 C++ 很容易:
Mat img = imread("c:\\Mytest.jpg", 0); // load grayscale
Mat thresh = ( im <= 10 ); // that's it already!
imshow("After",img);
waitKey(0);
关于c++ - opencv 图像二值化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23018382/