Merge branch 'master' of https://git.happytanuki.kr/HappyTanuki/Capstone_Design
This commit is contained in:
51
Homework/noise_denoise/main.cpp
Normal file
51
Homework/noise_denoise/main.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <iostream>
|
||||
#include "opencv2/opencv.hpp"
|
||||
|
||||
void make_salt_and_pepper_noise(cv::Mat& dst, float percent) {
|
||||
int num = dst.total() * percent;
|
||||
for (int i = 0; i < num; i++) {
|
||||
dst.at<uchar>(rand() % dst.rows, rand() % dst.cols) = (i % 2) * 255;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
cv::VideoCapture camera(0);
|
||||
if (!camera.isOpened()) {
|
||||
std::cerr << "isOpened()" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
std::uint32_t fps = camera.get(cv::CAP_PROP_FPS);
|
||||
cv::Mat src;
|
||||
|
||||
while (cv::waitKey(1000 / fps) != 27) {
|
||||
camera >> src;
|
||||
if (src.empty()) break;
|
||||
cv::imshow("preview", src);
|
||||
}
|
||||
cv::cvtColor(src, src, cv::COLOR_BGR2GRAY);
|
||||
|
||||
cv::Mat gaussian_noise(src.size(), CV_8UC1);
|
||||
//cv::Mat gaussian, salt_and_pepper, bilateral, median;
|
||||
|
||||
cv::randn(gaussian_noise, 0, 5);
|
||||
cv::Mat gaussian = src + gaussian_noise;
|
||||
|
||||
cv::Mat salt_and_pepper;
|
||||
src.copyTo(salt_and_pepper);
|
||||
make_salt_and_pepper_noise(salt_and_pepper, 0.1);
|
||||
|
||||
cv::Mat bilateral;
|
||||
cv::bilateralFilter(gaussian, bilateral, -1, 10, 5);
|
||||
|
||||
cv::Mat median;
|
||||
cv::medianBlur(salt_and_pepper, median, 3);
|
||||
|
||||
cv::imshow("src", src);
|
||||
cv::imshow("gaussian", gaussian);
|
||||
cv::imshow("salt_and_pepper", salt_and_pepper);
|
||||
cv::imshow("bilateral", bilateral);
|
||||
cv::imshow("median", median);
|
||||
|
||||
cv::waitKey();
|
||||
cv::destroyAllWindows();
|
||||
}
|
||||
@@ -131,6 +131,7 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
||||
@@ -14,4 +14,9 @@
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>소스 파일</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
BIN
Homework/noise_denoise/noise_denoise.zip
Normal file
BIN
Homework/noise_denoise/noise_denoise.zip
Normal file
Binary file not shown.
BIN
Homework/noise_denoise/스크린샷 2025-04-02 200316.png
(Stored with Git LFS)
Normal file
BIN
Homework/noise_denoise/스크린샷 2025-04-02 200316.png
(Stored with Git LFS)
Normal file
Binary file not shown.
Reference in New Issue
Block a user