#include
#include
using namespace cv;
using namespace std;
int main(int argc, const char* argv[])
{
Mat src = imread("D:/vcprojects/images/test.png", IMREAD_GRAYSCALE);
if (src.empty()) {
printf("could not load image...\n");
return -1;
}
namedWindow("input", WINDOW_AUTOSIZE);
imshow("input", src);
double minVal; double maxVal; Point minLoc; Point maxLoc;
minMaxLoc(src, &minVal, &maxVal, &minLoc, &maxLoc, Mat());
printf("min: %.2f, max: %.2f \n", minVal, maxVal);
printf("min loc: (%d, %d) \n", minLoc.x, minLoc.y);
printf("max loc: (%d, %d)\n", maxLoc.x, maxLoc.y);
// 彩色图像 三通道的 均值与方差
src = imread("D:/vcprojects/images/test.png");
Mat means, stddev;
meanStdDev(src, means, stddev);
printf("blue channel->> mean: %.2f, stddev: %.2f\n", means.at<double>(0, 0), stddev.at<double>(0, 0));
printf("green channel->> mean: %.2f, stddev: %.2f\n", means.at<double>(1, 0), stddev.at<double>(1, 0));
printf("red channel->> mean: %.2f, stddev: %.2f\n", means.at<double>(2, 0), stddev.at<double>(2, 0));
waitKey(0);
return 0;
}
重要函数 | 功能 |
---|---|
minMaxLoc(src,minVal,maxVal,minLoc,maxLoc,mask) | 在矩阵src中找到最小值和最大值并返回其位置 |
meanStdDev(src,mean,stddev) | 计算矩阵src中未被隐蔽的像素的平均值和标准差,多通道的话则以每个通道为基础计算 |
#include
#include
using namespace cv;
using namespace std;
int main(int argc, const char* argv[])
{
Mat src = imread("D:/vcprojects/images/test.png");
if (src.empty()) {
printf("could not load image...\n");
return -1;
}
namedWindow("input", WINDOW_AUTOSIZE);
imshow("input", src);
Mat gray, gray_f;
cvtColor(src, gray, COLOR_BGR2GRAY);
// 转换为浮点数类型数组
gray.convertTo(gray, CV_32F);
// scale and shift by NORM_MINMAX
Mat dst = Mat::zeros(gray.size(), CV_32FC1);
normalize(gray, dst, 1.0, 0, NORM_MINMAX);
Mat result = dst * 255;
result.convertTo(dst, CV_8UC1);
imshow("NORM_MINMAX", dst);
// scale and shift by NORM_INF
normalize(gray, dst, 1.0, 0, NORM_INF);
result = dst * 255;
result.convertTo(dst, CV_8UC1);
imshow("NORM_INF", dst);
// scale and shift by NORM_L1
normalize(gray, dst, 1.0, 0, NORM_L1);
result = dst * 10000000;
result.convertTo(dst, CV_8UC1);
imshow("NORM_L1", dst);
// scale and shift by NORM_L2
normalize(gray, dst, 1.0, 0, NORM_L2);
result = dst * 10000;
result.convertTo(dst, CV_8UC1);
imshow("NORM_L2", dst);
waitKey(0);
return 0;
}
重要函数 | 功能 |
---|---|
normalize(src,dst,alpha,beta,normType) | 根据normType的值把src归一化或映射到一个特定范围内并放入dst |
normType
- NORM_INF
- NORM_L1
- NORM_L2
- NORM_MINMAX
具体参考《学习OpenCV3》第124页
#include
#include
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
// 打开摄像头
// VideoCapture capture(0);
// 打开文件
VideoCapture capture;
capture.open("D:/vcprojects/images/video.avi");
if (!capture.isOpened()) {
printf("could not read this video file...\n");
return -1;
}
Size S = Size((int)capture.get(CAP_PROP_FRAME_WIDTH),
(int)capture.get(CAP_PROP_FRAME_HEIGHT));
int fps = capture.get(CAP_PROP_FPS);
printf("current fps : %d \n", fps);
VideoWriter writer("D:/test.mp4", VideoWriter::fourcc('D', 'I', 'V', 'X'), fps, S, true);
Mat frame;
namedWindow("camera-demo", WINDOW_AUTOSIZE);
while (capture.read(frame)) {
imshow("camera-demo", frame);
writer.write(frame);
char c = waitKey(50);
if (c == 27) {
break;
}
}
capture.release();
writer.release();
waitKey(0);
return 0;
}
输出视频。
cv::VideoCapture类的使用
VideoWriter的使用
需要注意的是,博主在使用VideoWriter时的cv_FOURCC()显示未被定义,因此改为了VideoWriter::FOURCC。
具体原因有时间再去stackoverflow看看。
一些数学知识未掌握。
没有很深入的了解C++,导致一些“类”之类的有时候看不明白。
每天学三个知识点太慢,不知道该怎么应用。接下里要去寻找应用的场景并且及时去复习以前的知识。