-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopencv_ground_truth.cpp
More file actions
39 lines (31 loc) · 1.2 KB
/
opencv_ground_truth.cpp
File metadata and controls
39 lines (31 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>
int main(int argc, char** argv) {
// Check if input path is provided
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " <input_image_path>" << std::endl;
return -1;
}
// Get input path from command line argument
std::string inputPath = argv[1];
// Load image
cv::Mat src = cv::imread(inputPath, cv::IMREAD_GRAYSCALE);
if (src.empty()) {
std::cerr << "Error: Could not load image from " << inputPath << std::endl;
return -1;
}
// Create temporary image for processing
cv::Mat tmp;
// Perform erosion with kernel size 5
cv::Mat kernel = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(5, 5));
cv::erode(src, tmp, kernel);
// Perform dilation with kernel size 5
cv::dilate(tmp, tmp, kernel);
// Generate output filename by adding suffix to input filename
std::string outputPath = inputPath.substr(0, inputPath.find_last_of('.')) + "-opencv-processed.png";
// Save the processed image
cv::imwrite(outputPath, tmp);
std::cout << "Processing completed! Output saved to: " << outputPath << std::endl;
return 0;
}