用imwrite写图像,确定地址没问题,但是为什么写不进去???也不显示图像呢????
代码如下:#include<iostream>
#include<string>
#include<sstream>
#include<opencv2\core.hpp>
#include<opencv2/highgui.hpp>
using namespace std;
using namespace cv;
int main(int argc, char * argv[]) {
Mat img = imread("1.jpg");
Mat gray = imread("1.jpg",0);
imwrite("1_gray.jpg", gray);//写图像
//通过opencv函数获取图像像素
int myrow = img.cols - 1;
int mycol = img.rows - 1;
Vec3b pixel = img.at<Vec3b>(myrow, mycol);
cout << "ixel value(B,G,R)" << (int)pixel[0] << "," << (int)pixel[1] << "," << (int)pixel[2] << ")" << endl;
namedWindow("test_BGR", CV_WINDOW_AUTOSIZE);
namedWindow("test_gray", CV_WINDOW_AUTOSIZE);
imshow("test_BGR", img);
imshow("test_gray", gray);
waitKey(0);
return 0;
}
|