Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Unable to operate 2 arrays due to Assertion failed (type2 == CV_64F && (sz2.height == 1 || sz 2.height == 4)) in cv::arithm_op

I am trying to operate 2 arrays (images) but my code -Opencv by example chapter 6- always crashes due to -I have found - a diffence value in the Mat Array property Step. One of the images -1st frame- comes from a directory and is read with

while (images.read(frame))... The other one had been read with light_pattern = imread(samples::findFile(light_pattern_file), 0);

When a function is called, to remove light, it crashes because "Sizes of input arguments do not match (The operation is neither 'array op array' ..."

Mat removeLight(Mat img, Mat pattern) { Mat aux;

// Require change our image to 32 float for division
Mat img32, pattern32;
img.convertTo(img32, CV_32F);
pattern.convertTo(pattern32, CV_32F);
// Divide the frame image by the pattern 
//Sizes of input arguments do not match (The operation is neither 'array op array'

aux = 1 - (img32 / pattern32);
// Scale it to convert o 8bit format
aux = aux * 255;
// Convert 8 bits format
aux.convertTo(aux, CV_8U);
//equalizeHist( aux, aux );
// aux = pattern - img;
return aux;

}

Checking the structure of the input arrays, I found out that their Mat Step value differs. One being {960, 3}, the other one {320, 1}.

I have unsuccesfully tried to convert either one to fit the other one. Not possible yet. I would like to know whether I can read(frame) in a way that I get it, similar Step to the one that comes from the imread(file_pattern, 0).

click to hide/show revision 2
None

updated 2019-10-21 00:31:19 -0600

berak gravatar image

Unable to operate 2 arrays due to Assertion failed (type2 == CV_64F && (sz2.height == 1 || sz 2.height == 4)) in cv::arithm_op

I am trying to operate 2 arrays (images) but my code -Opencv by example chapter 6- always crashes due to -I have found - a diffence value in the Mat Array property Step. One of the images -1st frame- comes from a directory and is read with

while (images.read(frame))...
(images.read(frame))...

The other one had been read with with

light_pattern = imread(samples::findFile(light_pattern_file), 0);

0);

When a function is called, to remove light, it crashes because

"Sizes of input arguments do not match (The operation is neither 'array op array' ..."

..." Mat removeLight(Mat img, Mat pattern) { Mat aux;

aux;

    // Require change our image to 32 float for division
 Mat img32, pattern32;
 img.convertTo(img32, CV_32F);
 pattern.convertTo(pattern32, CV_32F);
 // Divide the frame image by the pattern 
 //Sizes of input arguments do not match (The operation is neither 'array op array'

 aux = 1 - (img32 / pattern32);
 // Scale it to convert o 8bit format
 aux = aux * 255;
 // Convert 8 bits format
 aux.convertTo(aux, CV_8U);
 //equalizeHist( aux, aux );
 // aux = pattern - img;
 return aux;
}

}

Checking the structure of the input arrays, I found out that their Mat Step value differs. One being {960, 3}, the other one {320, 1}.

I have unsuccesfully tried to convert either one to fit the other one. Not possible yet. I would like to know whether I can read(frame) in a way that I get it, similar Step to the one that comes from the imread(file_pattern, 0).