Resize output of 3-channel and 1-channel of the same image does not match.

asked 2017-12-07 03:29:41 -0600

sargam.p gravatar image

updated 2017-12-08 03:18:00 -0600

berak gravatar image

I have been working on OpenCV's resize function. I resized a one channel input image , this is my output1. And then converted input image to 3 channel by keeping the other two channels zero, then resized this image by the same factor. The 3 channel output's R channel bits does not match with output1 when run on ARM processor.

It would be really helpful if anyone can figure out what the problem is. Thanks in advance.

#include "opencv2/highgui/highgui.hpp"
#include <opencv2/core/core.hpp>
#include <iostream>
#include <opencv2\imgproc\imgproc.hpp>

using namespace std;
using namespace cv;
int main()
{
    Mat input1 = imread("data/misc/camera/Lighthouse.jpg", IMREAD_GRAYSCALE);
    Mat input2(input1.rows, input1.cols, CV_8UC3);
    //converting 1 channel image to 3 channel
    for (int i = 0; i < input2.rows; i++)
    {
        for (int j = 0; j < input2.cols; j++)
        {
            input2.at<Vec3b>(i, j)[0] = input1.at<uchar>(i, j);
            input2.at<Vec3b>(i, j)[1] = 0;
            input2.at<Vec3b>(i, j)[2] = 0;
        }
    }
    double scale_x = 0.1, scale_y = 0.1;
    Mat output1(input1.rows*scale_y, input1.cols*scale_x, CV_8UC1), output2(input2.rows*scale_y, input2.cols*scale_x, CV_8UC3);
    Mat output3(input1.rows*scale_y, input1.cols*scale_x, CV_8UC1);
    resize(input1, output1, output1.size(), 0, 0, CV_INTER_LINEAR);
    resize(input2, output2, output2.size(), 0, 0, CV_INTER_LINEAR);
    //converting 3 channel image to 1 channel
    for (int i = 0; i < output2.rows; i++)
    {
        for (int j = 0; j < output2.cols; j++)
        {
            output3.at<uchar>(i, j) = output2.at<Vec3b>(i, j)[0];
        }
    }
    int flag = 0, diff, max = 0;
    //comparing the outputs
    for (int i = 0; i < output1.rows; i++)
    {
        for (int j = 0; j < output1.cols; j++)
        {
            if (output3.at<uchar>(i, j) != output1.at<uchar>(i, j))
            {
                flag = 1;
                if (flag)
                {
                    printf("Mismatch!!\n");
                    break;
                }
            }
        }
        if (flag) break;
    }
    return 0;
}`
edit retag flag offensive close merge delete

Comments

1

I have added the code. When i run this code on Windows using opencv 3.1, there is no mismatch. But running the same code on ARM processor using opencv android sdk gives mismatch.

sargam.p gravatar imagesargam.p ( 2017-12-08 03:19:08 -0600 )edit
1

try to insert printf("Mismatch %d != %d!!\n",output3.at<uchar>(i, j) ,output1.at<uchar>(i, j));

First loop you use merge function

Second loop use split function

LBerger gravatar imageLBerger ( 2017-12-08 03:38:57 -0600 )edit