i have implemented an error level analysis algorithm using c++(opencv version 2.4) and i want to build a python wrapper for it using cython. I have read some part of the documentation of cython for c++ but it did not help me and moreover i did not find any extra information for implementing the wrapper online. It would be really great if someone could guide me and help me solve this problem.
This is my code for which i want to build a pyhton wrapper:
#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("lena.jpeg", input_image, parameters);// Reading temp image from the disk
compressed_image = cv::imread("lena.jpeg");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 factorptr_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;
}
https://github.com/shreyneil/image_test/blob/master/ela.cpp
Contributions are welcome. Thank you.