#include <iostream>
#include <string>
#include <sstream>
using namespace std;
//Opencv includes
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
using namespace cv;
int test0(){
//Read images
Mat color = imread("./Opencv4_images/lena.jpg");
Mat gray = imread("./Opencv4_images/lena.jpg",IMREAD_GRAYSCALE);
if (!color.data) //Check for invalid input
{
cout << "Could not open or find the image" << endl;
return -1;
}
// Write images
imwrite("lenaGray.jpg", gray);
//Get same pixel with opencv function
int myRow = color.cols - 1;
int myCol = color.rows - 1;
//使用at方法是一个模板函数,模板参数T定义了返回值类型,能获取到像素点。
//Vec3b类型,是一个3个uchar组成的动态数组。
Vec3b pixel = color.at<Vec3b>(myRow, myCol);
cout << "Pixel value (B,G,R):( " << (int)pixel[0] << "," <<
(int)pixel[1] << "," << (int)pixel[2] << ")" << endl;
//Show images
imshow("Lena BGR", color);
imshow("Lena Gray", gray);
// Wait for any key press
waitKey(0);
return 0;
}
int test1(){
VideoCapture cap(0);//open the default camera
if (!cap.isOpened()) //check if we succeeded
{
return -1;
}
namedWindow("VIdeo",1);
for (;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
if (frame.empty())
{
return 0;
}
imshow("Video",frame);
if (waitKey(30) >= 0)
break;
}
// Relese the camera or video cap
cap.release();
return 0;
}