I do the following test, however, the result is not that good, because I wish that GAPI could improve a lot. I don't know whether I did something wrong, I hope you can help me correct, Thanks so much!
My test environment are OpenCV4.2 official build, Windows 10 x64, VS2019 Release x64,i7-8700K.
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/gapi.hpp>
#include <opencv2/gapi/core.hpp>
#include <opencv2/gapi/imgproc.hpp>
std::string image_path = "1.png";
cv::Mat GAPITEST(const cv::Mat& input_frame)
{
cv::Mat output_frame;
cv::GMat in;
cv::GMat vga = cv::gapi::resize(in, cv::Size(), 0.5, 0.5);
cv::GMat gray = cv::gapi::BGR2Gray(vga);
cv::GMat blurred = cv::gapi::blur(gray, cv::Size(5, 5));
cv::GMat out = cv::gapi::Canny(blurred, 32, 128, 3);
cv::GComputation ac(in, out);
int64 t0 = cv::getTickCount();
for(int i=0;i<200;i++)
ac.apply(input_frame, output_frame);
int64 t1 = cv::getTickCount();
std::cout <<__func__<< "\t seconds:" << (t1 - t0) / cv::getTickFrequency()<<std::endl;
return output_frame;
}
cv::Mat TraditionalTEST(const cv::Mat& input_frame)
{
cv::Mat output_frame;
cv::Mat vga;
cv::Mat gray;
cv::Mat blurred;
int64 t0 = cv::getTickCount();
for (int i = 0; i < 200; i++)
{
cv::resize(input_frame,vga, cv::Size(), 0.5, 0.5);
cv::cvtColor(vga, gray, cv::COLOR_BGR2GRAY);
cv::blur(gray, blurred,cv::Size(5,5));
cv::Canny(blurred,output_frame,32,128,3);
}
int64 t1 = cv::getTickCount();
std::cout << __func__ << "\t seconds:" << (t1 - t0) / cv::getTickFrequency()<<std::endl;
return output_frame;
}
int main()
{
cv::Mat input_frame = cv::imread(image_path);
cv::imshow("input_frame",input_frame);
cv::waitKey(100);
auto result1 = GAPITEST(input_frame);
auto result2 = TraditionalTEST(input_frame);
//check result whether identical or not.
bool eq = cv::countNonZero(result1 != result2) == 0;
std::cout << "result equal "<< eq;
return 0;
}
outut
GAPITEST seconds:4.92153
TraditionalTEST seconds:4.68761
result equal 1