#include "opencv2/opencv.hpp"
#include<iostream>
#include<stdint.h>
using namespace cv;
using namespace std;
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);
}
}
Mat processframe(Mat& frame)
{
Mat img_roberts_1;
roberts(frame, img_roberts_1, CV_32FC1, 1, 0);
Mat img_roberts_2;
roberts(frame, 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);
return edge;
}
bool covert_to_edge_style(string src, string dst)
{
VideoCapture cap(src);// open the default camera
if (!cap.isOpened()) // check if we succeeded
return -1;
double rate = cap.get(CV_CAP_PROP_FPS);
int width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
int height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
Size videoSize(width, height);
VideoWriter writer(dst, CV_FOURCC('M', 'J', 'P', 'G'), rate, videoSize);
//namedWindow("src");
for (; ; )
{
Mat frame;
cap >> frame; // get a new frame from camera
if (frame.empty())
break;
Mat edge = processframe(frame);
writer << edge;
//namedWindow("edge intensity", CV_WINDOW_AUTOSIZE);
//imshow("edge intensity", edge);
//imshow("src", frame);
//if (waitKey(10) >= 0)
// break;
}
return 0;
}
int main(void)
{
while (1)
{
printf("--------------------------------------------------------------\n");
printf("please input your video path to be coverted:\n");
char src[1024];
fgets(src, 100, stdin);
if (src[strlen(src) - 1] == '\n')
src[strlen(src) - 1] = '\0';
printf("please input output video path:\n");
char dst[1024];
fgets(dst, 100, stdin);
if (dst[strlen(dst) - 1] == '\n')
dst[strlen(dst) - 1] = '\0';
covert_to_edge_style(src, dst);
printf("covertion finished!! \n");
}
}
#include<iostream>
#include<stdint.h>
using namespace cv;
using namespace std;
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);
}
}
Mat processframe(Mat& frame)
{
Mat img_roberts_1;
roberts(frame, img_roberts_1, CV_32FC1, 1, 0);
Mat img_roberts_2;
roberts(frame, 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);
return edge;
}
bool covert_to_edge_style(string src, string dst)
{
VideoCapture cap(src);// open the default camera
if (!cap.isOpened()) // check if we succeeded
return -1;
double rate = cap.get(CV_CAP_PROP_FPS);
int width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
int height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
Size videoSize(width, height);
VideoWriter writer(dst, CV_FOURCC('M', 'J', 'P', 'G'), rate, videoSize);
//namedWindow("src");
for (; ; )
{
Mat frame;
cap >> frame; // get a new frame from camera
if (frame.empty())
break;
Mat edge = processframe(frame);
writer << edge;
//namedWindow("edge intensity", CV_WINDOW_AUTOSIZE);
//imshow("edge intensity", edge);
//imshow("src", frame);
//if (waitKey(10) >= 0)
// break;
}
return 0;
}
int main(void)
{
while (1)
{
printf("--------------------------------------------------------------\n");
printf("please input your video path to be coverted:\n");
char src[1024];
fgets(src, 100, stdin);
if (src[strlen(src) - 1] == '\n')
src[strlen(src) - 1] = '\0';
printf("please input output video path:\n");
char dst[1024];
fgets(dst, 100, stdin);
if (dst[strlen(dst) - 1] == '\n')
dst[strlen(dst) - 1] = '\0';
covert_to_edge_style(src, dst);
printf("covertion finished!! \n");
}
}