forked from opencv/opencv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.