-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsobel.cpp
48 lines (39 loc) · 1.08 KB
/
sobel.cpp
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
#include <stdio.h>
#include <time.h>
#include <string>
#include <opencv2/opencv.hpp>
#include "sobel.h"
using namespace cv;
int main(int argc, char** argv)
{
clock_t start, end;
double time_taken;
if (argc != 2) {
printf("Please input picture directory\n");
return -1;
}
Mat image, gray_img, omp_img;
image = imread(argv[1], 1);
if (!image.data) {
printf("No image data\n");
return -1;
}
cvtColor(image, gray_img, COLOR_RGB2GRAY);
omp_img = omp_img.zeros(gray_img.size(), gray_img.type());
start = clock();
sobel_filter(&gray_img, &omp_img);
end = clock();
time_taken = (double)(end - start);
printf("Time taken is %lf\n", time_taken);
#ifdef DEBUG
namedWindow("Original Image", WINDOW_NORMAL);
imshow("Original Image", image);
namedWindow("Sobel Image", WINDOW_NORMAL);
imshow("Sobel Image", omp_img);
waitKey(0);
#endif
std::string file(argv[1]);
std::string extension = file.substr(file.find_last_of("."));
imwrite(std::string("pics/output") + extension , omp_img);
return 0;
}