-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfltr.cpp
65 lines (50 loc) · 1.75 KB
/
fltr.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "HLS/hls.h"
#include <cstdio>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int kernelArray[4][3][3] = {{{-1,-1,-1},{2,2,2},{-1,-1,-1}},
{{-1,2,-1},{-1,2,-1},{-1,2,-1}},
{{-1,-1,2},{-1,2,-1},{2,-1,-1}},
{{2,-1,-1},{-1,2,-1},{-1,-1,2}}};
extern "C" uchar* grayscale(uchar* image, int rows, int cols, int channels, int step) {
uchar* grayImage = (uchar*)malloc(sizeof(uchar)*rows*cols);
memset(grayImage, 0, sizeof(uchar)*rows*cols);
for(int y = 0; y < rows; y++) {
for (int x = 0; x < cols; x++) {
int blue = (int)image[channels*x + step*y];
int green = (int)image[channels*x + step*y + 1];
int red = (int)image[channels*x + step*y + 2];
grayImage[x + cols*y] = (uchar)(.3*red) + (.59 * green) + (.11 * blue);
}
}
return grayImage;
}
int main(int argc, char** argv )
{
if ( argc < 3 )
{
printf("usage: DisplayImage.out <Image_Path>\n");
return -1;
}
Mat image;
printf ("%s \n", argv[1]);
image = imread( argv[1], 1 );
if (image.empty()) // !image.data )
{
printf("No image data \n");
return -1;
}
Mat processedImage;
if (strcmp(argv[2], "-g") == 0)
{
unsigned char* grayImageData = grayscale(image.data, image.rows, image.cols, image.channels(), image.step);
processedImage = Mat(image.rows, image.cols, CV_8UC1, grayImageData);
}
//namedWindow("Display Image", WINDOW_AUTOSIZE );
//imshow("Display Image", processedImage);
//waitKey(0);
imwrite (strcat(argv[2], argv[1]), processedImage);
printf ("%s \n", strcat(argv[2], argv[1]));
return 0;
}