【C++】【OpenCv】图片加噪声处理,计时,及键盘事件响应捕捉
生活随笔
收集整理的這篇文章主要介紹了
【C++】【OpenCv】图片加噪声处理,计时,及键盘事件响应捕捉
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
圖像噪聲添加
cv::Mat addGuassianNoise(cv::Mat& src, double a, double b) {cv::Mat temp = src.clone();cv::Mat dst(src.size(), src.type());
?// Construct a matrix containing Gaussian noisecv::Mat noise(temp.size(), temp.type());cv::RNG rng(time(NULL));// Gaussian distribution; The mean is a, and the standard deviation is brng.fill(noise, cv::RNG::NORMAL, a, b);
?add(temp, noise, dst);return dst;
}
參考資料https://docs.opencv.org/master/d1/dd6/classcv_1_1RNG.html#ad26f2b09d9868cf108e84c9814aa682d
rng.fill
?
?
鼠標事件捕獲
#include <conio.h>
#include <iostream>
?
using namespace std;
?
int main()
{int ch;while (1) {if (_kbhit()) {//如果有按鍵按下,則_kbhit()函數返回真ch = _getch();//使用_getch()函數獲取按下的鍵值cout << ch;if (ch == 27) { break; }//當按下ESC時循環,ESC鍵的鍵值時27.}}system("pause");
}
幀率處理計算與保存
std::ofstream out_frame(FLAGS_deptrum_prefix + "frame_info.txt", std::ios::out | std::ios::app);double start_time = (double) cv::getTickCount();int count = 0;if (out_frame.is_open()) {out_frame << "Times passed in seconds"<< "\t"<< " ? The Frame of average\t"<< "\n";while (!kbhit()) {double t1 = (double) cv::getTickCount();ProcessImage(deptrum_depth, input_path.string(), path_bg, path_rgb, temperature, true);double t2 = ((double) cv::getTickCount() - t1) / cv::getTickFrequency();printf("\n\n");printf("#### current frame consume time is %f", t2);printf("\n\n");count++;out_frame << t2 << "\t\t" << (int) (1 / t2) << "\t\n";}}out_frame.close();
?
?
總結
以上是生活随笔為你收集整理的【C++】【OpenCv】图片加噪声处理,计时,及键盘事件响应捕捉的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 打一针破伤风多少钱
- 下一篇: 【MATLAB】————拷贝指定文件路径