deepin-ocr/3rdparty/opencv-4.5.4/samples/cpp/ela.cpp
wangzhengyang 718c41634f feat: 切换后端至PaddleOCR-NCNN,切换工程为CMake
1.项目后端整体迁移至PaddleOCR-NCNN算法,已通过基本的兼容性测试
2.工程改为使用CMake组织,后续为了更好地兼容第三方库,不再提供QMake工程
3.重整权利声明文件,重整代码工程,确保最小化侵权风险

Log: 切换后端至PaddleOCR-NCNN,切换工程为CMake
Change-Id: I4d5d2c5d37505a4a24b389b1a4c5d12f17bfa38c
2022-05-10 10:22:11 +08:00

68 lines
2.1 KiB
C++

/**
@file ela.cpp
@author Alessandro de Oliveira Faria (A.K.A. CABELO)
@brief Error Level Analysis (ELA) permits identifying areas within an image that are at different compression levels. With JPEG images, the entire picture should be at roughly the same level. If a section of the image is at a significantly different error level, then it likely indicates a digital modification. This example allows to see visually the changes made in a JPG image based in it's compression error analysis. Questions and suggestions email to: Alessandro de Oliveira Faria cabelo[at]opensuse[dot]org or OpenCV Team.
@date Jun 24, 2018
*/
#include <opencv2/highgui.hpp>
#include <iostream>
using namespace cv;
int scale_value = 7;
int quality = 95;
Mat image;
Mat compressed_img;
const char* decodedwin = "the recompressed image";
const char* diffwin = "scaled difference between the original and recompressed images";
static void processImage(int , void*)
{
Mat Ela;
// Compression jpeg
std::vector<int> compressing_factor;
std::vector<uchar> buf;
compressing_factor.push_back(IMWRITE_JPEG_QUALITY);
compressing_factor.push_back(quality);
imencode(".jpg", image, buf, compressing_factor);
compressed_img = imdecode(buf, 1);
Mat output;
absdiff(image,compressed_img,output);
output.convertTo(Ela, CV_8UC3, scale_value);
// Shows processed image
imshow(decodedwin, compressed_img);
imshow(diffwin, Ela);
}
int main (int argc, char* argv[])
{
CommandLineParser parser(argc, argv, "{ input i | ela_modified.jpg | Input image to calculate ELA algorithm. }");
parser.about("\nJpeg Recompression Example:\n");
parser.printMessage();
// Read the new image
image = imread(samples::findFile(parser.get<String>("input")));
// Check image
if (!image.empty())
{
processImage(0, 0);
createTrackbar("Scale", diffwin, &scale_value, 100, processImage);
createTrackbar("Quality", diffwin, &quality, 100, processImage);
waitKey(0);
}
else
{
std::cout << "> Error in load image\n";
}
return 0;
}