#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <vector>
const char* keys =
"{ help h | | Print help message. }"
"{ input i | | Input image to calc ELA algorithm. }";
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;
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);
imshow(decodedwin, compressed_img);
imshow(diffwin, Ela);
}
int main (int argc, char* argv[])
{
CommandLineParser parser(argc, argv, keys);
if(argc == 1 || parser.has("help"))
{
parser.printMessage();
std::cout << "\nJpeg Recompression Example:\n\t" << argv[0] << " --input=../../data/ela_modified.jpg\n";
return 0;
}
if(parser.has("input"))
{
image = imread(parser.get<String>("input"));
}
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;
}