|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
|
|
|
|
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, "{ input i | ela_modified.jpg | Input image to calculate ELA algorithm. }");
|
|
|
parser.about("\nJpeg Recompression Example:\n");
|
|
|
parser.printMessage();
|
|
|
|
|
|
|
|
|
image = imread(samples::findFile(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;
|
|
|
}
|
|
|
|