-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedge.cpp
More file actions
56 lines (40 loc) · 1.03 KB
/
edge.cpp
File metadata and controls
56 lines (40 loc) · 1.03 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
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include<opencv2/core/core.hpp>
using namespace cv;
using namespace std;
int main(){
int bysum,bxsum,L;
Mat src=imread("im.jpg",0);
namedWindow( "OP", WINDOW_NORMAL );
Mat op(src.rows,src.cols,CV_8UC1,Scalar(255));
namedWindow( "IP", WINDOW_NORMAL );
imshow("IP",src);
int VAL=0;
while(1){
createTrackbar("VAL","OP",&VAL,255);
for(int i=0;i<src.rows;i++){
for(int j=0;j<src.cols;j++){
bxsum=bysum=0;
if(i-1>0 && i+1 <src.rows){
bxsum=src.at<uchar>(i+1,j)/2-src.at<uchar>(i-1,j)/2;
}
if(j-1>0 && j+1 < src.cols){
bysum=src.at<uchar>(i,j-1)/2-src.at<uchar>(i,j+1)/2;
}
op.at<uchar>(i,j)=255-sqrt(bxsum*bxsum + bysum*bysum);
L=255-op.at<uchar>(i,j);
if(L>VAL)
op.at<uchar>(i,j)=0;
else
op.at<uchar>(i,j)=255;
}
}
imshow("OP",op);
waitKey(2);
}
return 0;
}