我正在尝试使用openCV导入图像,并为每个像素提取相应的灰度值。我决定使用openCV,因为它很简单,但我遇到了问题。当我运行程序时,它会报告这些错误:
计算机上没有opencv_core249。
计算机上没有opencv_highgiu249
计算机上没有opencv_imgproc249
我正在使用openCV版本2.4.9和Visual Studio 2015 Enterprise。这是代码:
#include <opencv2/opencv.hpp>
using namespace cv;
#include <fstream>
using namespace std;
int main(int argc, char** argv)
{
Mat colorImage = imread("blackwhite.png");
// First convert the image to grayscale.
Mat grayImage;
cvtColor(colorImage, grayImage, CV_RGB2GRAY);
// Then apply thresholding to make it binary.
Mat binaryImage(grayImage.size(), grayImage.type());
threshold(grayImage, binaryImage, 128, 255, CV_THRESH_BINARY);
// Open the file in write mode.
ofstream outputFile;
outputFile.open("MyFile.txt");
// Iterate through pixels.
for (int r = 0; r < binaryImage.rows; r++)
{
for (int c = 0; c < binaryImage.cols; c++)
{
int pixel = binaryImage.at<uchar>(r, c);
outputFile << pixel << '\t';
}
outputFile << endl;
}
// Close the file.
outputFile.close();
return 0;
}