Created
May 3, 2020 14:29
-
-
Save YHaruoka/6c6ed5fe707c2a248b94fed43e626e92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <opencv2/opencv.hpp> | |
int main() { | |
// 画像の入力 | |
cv::Mat input_image = cv::imread("input.jpg", 0); | |
cv::Mat sobel_image, output_image; | |
/* Sobelフィルタ (3×3) | |
-1 0 1 | |
-2 0 2 | |
-1 0 1 */ | |
// Sobelフィルタの処理(入力画像,出力画像,出力タイプ,x方向の微分次数,y方向の微分次数,フィルタサイズ) | |
cv::Sobel(input_image, sobel_image, CV_32F, 1, 0, 3); // x方向の微分フィルタ | |
// cv::Sobel(input_image, sobel_image, CV_32F, 0, 1, 3); // y方向の微分フィルタ | |
// convertScaleAbs(=スケーリング後に絶対値を計算し,結果を8ビットに変換) | |
cv::convertScaleAbs(sobel_image, output_image, 1, 0); | |
// 閾値以上の場合にエッジ(=白)と見なす(入力画像,出力画像,閾値,最大値,閾値タイプ) | |
// cv::threshold(output_image, output_image, 64, 255, cv::THRESH_BINARY); | |
// 画像の保存と表示 | |
cv::imwrite("output.jpg", output_image); | |
cv::imshow("Sobel_Filter_Result", output_image); | |
cv::waitKey(0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment