과제 세이브

This commit is contained in:
2025-04-23 19:52:02 +09:00
parent 0698459104
commit bed4860776
4 changed files with 213 additions and 0 deletions

41
Homework/edge/main.cpp Normal file
View File

@@ -0,0 +1,41 @@
#include <iostream>
#include "opencv2/opencv.hpp"
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 dx, dy, fmag, mag, phase;
cv::Sobel(src, dx, CV_32FC1, 1, 0);
cv::Sobel(src, dy, CV_32FC1, 0, 1);
cv::magnitude(dx, dy, fmag);
fmag.convertTo(mag, CV_8UC1);
cv::phase(dx, dy, phase, true);
cv::normalize(phase, phase, 0, 255, cv::NORM_MINMAX);
phase.convertTo(phase, CV_8UC1);
cv::Mat edge = mag > 150;
cv::imshow("src", src);
cv::imshow("mag", mag);
cv::imshow("edge", edge);
cv::imshow("phase", phase);
cv::waitKey();
cv::destroyAllWindows();
}