use*_*743 4 opencv image-processing
如何计算图像的ELA?我想使用opencv http://fotoforensics.com/tutorial-ela.php获得类似的ELA图像
根据本教程,我以95%质量的jpeg图像重新保存图像,并使用absDiff方法计算源图像和重新保存图像之间的差异,但我得到的只是零差异.
有关如何计算两个图像之间的差异以获得错误级别的任何帮助,就像教程中的示例图像一样?
Eli*_*art 10
实现类似结果的关键是使用压缩率的变量值和比例因子,以便更容易可视化数据.
这是一个例子:我们有输入图像(左)和经过一些参数调整后处理后的图像(右):
正如预期的那样,带有圣诞帽的区域与图像的其余部分呈现出不同的压缩率.此结果与FotoForensics提供的结果非常相似:
通过对此代码进行一些调整,您可以获得更接近的结果.这个项目的源代码可以在我的Github上找到:
main.cpp:
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <vector>
// Control
int scale = 15,
quality = 75;
// Image containers
cv::Mat input_image,
compressed_image;
void processImage(int, void*)
{
// Setting up parameters and JPEG compression
std::vector<int> parameters;
parameters.push_back(CV_IMWRITE_JPEG_QUALITY);
parameters.push_back(quality);
cv::imwrite("temp.jpg", input_image, parameters);
// Reading temp image from the disk
compressed_image = cv::imread("temp.jpg");
if (compressed_image.empty())
{
std::cout << "> Error loading temp image" << std::endl;
exit(EXIT_FAILURE);
}
cv::Mat output_image = cv::Mat::zeros(input_image.size(), CV_8UC3);
// Compare values through matrices
for (int row = 0; row < input_image.rows; ++row)
{
const uchar* ptr_input = input_image.ptr<uchar>(row);
const uchar* ptr_compressed = compressed_image.ptr<uchar>(row);
uchar* ptr_out = output_image.ptr<uchar>(row);
for (int column = 0; column < input_image.cols; column++)
{
// Calc abs diff for each color channel multiplying by a scale factor
ptr_out[0] = abs(ptr_input[0] - ptr_compressed[0]) * scale;
ptr_out[1] = abs(ptr_input[1] - ptr_compressed[1]) * scale;
ptr_out[2] = abs(ptr_input[2] - ptr_compressed[2]) * scale;
ptr_input += 3;
ptr_compressed += 3;
ptr_out += 3;
}
}
// Shows processed image
cv::imshow("Error Level Analysis", output_image);
}
int main (int argc, char* argv[])
{
// Verifica se o número de parâmetros necessário foi informado
if (argc < 2)
{
std::cout << "> You need to provide an image as parameter" << std::endl;
return EXIT_FAILURE;
}
// Read the image
input_image = cv::imread(argv[1]);
// Check image load
if (input_image.empty())
{
std::cout << "> Error loading input image" << std::endl;
return EXIT_FAILURE;
}
// Set up window and trackbar
cv::namedWindow("Error Level Analysis", CV_WINDOW_AUTOSIZE);
cv::imshow("Error Level Analysis", input_image);
cv::createTrackbar("Scale", "Error Level Analysis", &scale, 100, processImage);
cv::createTrackbar("Quality", "Error Level Analysis", &quality, 100, processImage);
// Press 'q' to quit
while (char(cv::waitKey(0)) != 'q') {};
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
以下是一些用于构建此mash-up的好参考:
| 归档时间: |
|
| 查看次数: |
3662 次 |
| 最近记录: |