#include<opencv2/opencv.hpp>
#include<iostream>
#include<stdint.h>
using namespace std;
using namespace cv;
void conv2D(InputArray src, InputArray kernel, OutputArray dst, int ddepth, Point anchor = Point(-1, -1), int borderType = BORDER_DEFAULT)
{
Mat kernelFlip;
flip(kernel, kernelFlip,-1);
filter2D(src, dst, ddepth, kernelFlip, anchor, 0.0, borderType);
}
void roberts(InputArray src, OutputArray dst, int ddepth, int x = 1, int y = 0, int borderType = BORDER_DEFAULT)
{
CV_Assert(!(x == 0 && y == 0));
Mat roberts_1 = (Mat_<float>(2, 2) << 1, 0, 0, -1);
Mat roberts_2 = (Mat_<float>(2, 2) << 0, 1, -1, 0);
if (x != 0 && y == 0)
{
conv2D(src,roberts_1,dst,ddepth,Point(0,0),borderType);
}
if (y != 0 && x == 0)
{
conv2D(src, roberts_2, dst, ddepth, Point(1, 0), borderType);
}
}
int main(int argc, char* argv[])
{
Mat image = imread("mj1.jpg", CV_LOAD_IMAGE_GRAYSCALE);
if (!image.data)
{
cout << "no picture" << endl;
return -1;
}
Mat img_roberts_1;
roberts(image, img_roberts_1, CV_32FC1, 1, 0);
Mat img_roberts_2;
roberts(image, img_roberts_2, CV_32FC1, 0, 1);
Mat abs_img_roberts_1, abs_img_roberts_2;
convertScaleAbs(img_roberts_1, abs_img_roberts_1, 1, 0);
convertScaleAbs(img_roberts_2, abs_img_roberts_2, 1, 0);
Mat img_roberts_1_2, img_roberts_2_2, edge;
pow(img_roberts_1, 2.0, img_roberts_1_2);
pow(img_roberts_2, 2.0, img_roberts_2_2);
sqrt(img_roberts_1_2 + img_roberts_2_2, edge);
edge.convertTo(edge,CV_8UC1);
namedWindow("edge intensity", CV_WINDOW_AUTOSIZE);
imshow("edge intensity", edge);
waitKey(0);
return 0;
}
#include<iostream>
#include<stdint.h>
using namespace std;
using namespace cv;
void conv2D(InputArray src, InputArray kernel, OutputArray dst, int ddepth, Point anchor = Point(-1, -1), int borderType = BORDER_DEFAULT)
{
Mat kernelFlip;
flip(kernel, kernelFlip,-1);
filter2D(src, dst, ddepth, kernelFlip, anchor, 0.0, borderType);
}
void roberts(InputArray src, OutputArray dst, int ddepth, int x = 1, int y = 0, int borderType = BORDER_DEFAULT)
{
CV_Assert(!(x == 0 && y == 0));
Mat roberts_1 = (Mat_<float>(2, 2) << 1, 0, 0, -1);
Mat roberts_2 = (Mat_<float>(2, 2) << 0, 1, -1, 0);
if (x != 0 && y == 0)
{
conv2D(src,roberts_1,dst,ddepth,Point(0,0),borderType);
}
if (y != 0 && x == 0)
{
conv2D(src, roberts_2, dst, ddepth, Point(1, 0), borderType);
}
}
int main(int argc, char* argv[])
{
Mat image = imread("mj1.jpg", CV_LOAD_IMAGE_GRAYSCALE);
if (!image.data)
{
cout << "no picture" << endl;
return -1;
}
Mat img_roberts_1;
roberts(image, img_roberts_1, CV_32FC1, 1, 0);
Mat img_roberts_2;
roberts(image, img_roberts_2, CV_32FC1, 0, 1);
Mat abs_img_roberts_1, abs_img_roberts_2;
convertScaleAbs(img_roberts_1, abs_img_roberts_1, 1, 0);
convertScaleAbs(img_roberts_2, abs_img_roberts_2, 1, 0);
Mat img_roberts_1_2, img_roberts_2_2, edge;
pow(img_roberts_1, 2.0, img_roberts_1_2);
pow(img_roberts_2, 2.0, img_roberts_2_2);
sqrt(img_roberts_1_2 + img_roberts_2_2, edge);
edge.convertTo(edge,CV_8UC1);
namedWindow("edge intensity", CV_WINDOW_AUTOSIZE);
imshow("edge intensity", edge);
waitKey(0);
return 0;
}