My code works in Visual Studio using OpenCV. But its not showing output in an Android NDK
application, and its not showing an error
Below is my code.
void sow(Mat& img1, Mat& img2, Mat& out)
{
Mat result(img1.size(), CV_32FC4);
img2 = Mat(img1.size(), img1.type(), Scalar(186, 44, 28, 0));
for (int i = 0; i < img1.size().height; ++i){
for (int j = 0; j < img1.size().width; ++j){
for (int c = 0; c<img1.channels(); c++){ // Iterate through colors
//Formula
float target = (float)img1.at<uchar>(i, 4 * j + c) / 255.;
float blend = (float)img2.at<uchar>(i, 4 * j + c) / 255.;
if (blend > 0.5){
result.at<float>(i, 4 * j + c) = ((1 - (1 - target) * (1 - 2 * (blend - 0.5))));
}
else{
result.at<float>(i, 4 * j + c) = (target * (2 * blend));
}
}
}
}
result.convertTo(out, CV_8UC4, 255);
}
It works for me in Visual Studio with an 8UC3
image, but not with an 8UC4
image in Android. Other than n output in imageview, there is no error.
The same thing works for me in Android when I change the formula, but this formula works for me on Visual Studio . Some images work for me when I have the same code but different formula's in
if (blend > 0.5)
{
result.at<float>(i, 4 * j + c) = ((1 - (1 - target) * (1 - 2 * (blend - 0.5))));
}
else
{
result.at<float>(i, 4 * j + c) = (target * (2 * blend));
}
And they are showing output.
In the same way when I use :
void BL(Mat& img1, Mat& img2, Mat& out)
{
img2 = Mat(img1.size(), img1.type(), Scalar(186, 44, 28, 0));
max(img1, img2, out);
}
it shows output but when I use max(img1, img2, out);
in the same code its not showing output. And they all are working in Visual Studio but not in Android using NDK. I tested my JNI
and it is work correctly, the Java code is correct too.
input image :
Resultant image after result :