-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
79 lines (61 loc) · 2.67 KB
/
main.cpp
File metadata and controls
79 lines (61 loc) · 2.67 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// Created by nenec on 05/11/2024.
//
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <opencv2/core/utils/logger.hpp>
#include <iostream>
#include <fstream>
#include <chrono>
#include "MMops.h"
using namespace cv;
using namespace std;
int probe_size = 15;
int main( int argc, char** argv ) {
setLogLevel(utils::logging::LogLevel::LOG_LEVEL_SILENT);
//String img_name = "gsimage.jpg";
Mat frame = imread("./images/yourimage.jpg", IMREAD_GRAYSCALE);
Mat frameIn = imread("./images/yourimage.jpg", IMREAD_GRAYSCALE);
Mat element =cv::getStructuringElement(MORPH_ELLIPSE, Size(probe_size,probe_size));
copyMakeBorder(frame, frame, probe_size, probe_size, probe_size, probe_size, 0);
ofstream csvFile("path/to/file.csv");
csvFile << "size" << "time" << endl;
int times = 0;
while (times < 10) {
auto start = std::chrono::system_clock::now();
Mat erosionImg = Mat(frame.rows, frame.cols, CV_8UC1, cv::Scalar(0));
Mat dilationImg = Mat(frame.rows, frame.cols, CV_8UC1, cv::Scalar(0));
Mat closingImg = Mat(frame.rows, frame.cols, CV_8UC1, cv::Scalar(0));
Mat openingImg = Mat(frame.rows, frame.cols, CV_8UC1, cv::Scalar(0));
/*EROSION & DILATION*/
for (int i=0+probe_size; i<frame.rows-probe_size; i++) {
for (int j=0+probe_size; j<frame.cols-probe_size; j++) {
int erosion = erode(frame, element, i, j);
int dilation = dilate(frame, element, i, j);
erosionImg.at<uchar>(i,j) = erosion;
dilationImg.at<uchar>(i,j) = dilation;
}
}
/*OPENING & CLOSING*/
for (int i=0+probe_size; i<closingImg.rows-probe_size; i++) {
for (int j=0+probe_size; j<closingImg.cols-probe_size; j++) {
int opening = dilate(erosionImg, element, i, j);
int closing = erode(dilationImg, element, i, j);
closingImg.at<uchar>(i,j) = closing;
openingImg.at<uchar>(i,j) = opening;
}
}
auto end = std::chrono::system_clock::now();
auto time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
csvFile << frameIn.rows << "," << time.count() << endl;
times++;
}
//cout << "Time to perform Erosion, Dilation, Opening and Closing: " << time.count() << " millisec." << endl;
/*imshow("Source", frameIn); //original
imshow("Erosion", erosionImg);
imshow("Dilation", dilationImg);
imshow("Opening", openingImg);
imshow("Closing", closingImg);
waitKey();*/
return 0;
}