Skip to content

Commit

Permalink
Include ELA example (opencv#11819)
Browse files Browse the repository at this point in the history
* Include ELA example

* Include ELA example

* Include ELA example

* Include ELA example

* Include ELA example

* Include ELA example

* Include ELA example

* Include ELA example

* Include ELA example

* Include ELA example

* Include ELA example

* did some code cleanup

* fixed compile error
  • Loading branch information
cabelo authored and vpisarev committed Jun 26, 2018
1 parent b39cd06 commit cc8db99
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions samples/cpp/ela.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
@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/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;

// 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, 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"))
{
// Read the new image
image = imread(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;
}
Binary file added samples/data/ela_modified.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/data/ela_original.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cc8db99

Please sign in to comment.