Ask Your Question
0

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

asked 2019-10-20 17:09:13 -0600

fabianc20 gravatar image

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

berak gravatar image

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).

edit retag flag offensive close merge delete

Comments

which opencv version ?

berak gravatar imageberak ( 2019-10-21 00:42:46 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
2

answered 2019-10-21 10:24:45 -0600

fabianc20 gravatar image

updated 2019-10-23 21:03:07 -0600

supra56 gravatar image

Berak version is 4.1.1, VS 2109 ver 16.3.5

I got it to work,

Ultimately the function that calls removeLitght, must past a {360,1} Step value... So I found this cvtColor, which is the video equivalent of the image converTo ---> and then what ever you need. So BGR->Gray made it for me. Thanks. I guess by the time "Opencv by Example" was released this was not an issue.

Thanks Fabian

See the pice of working code.

Mat frame, myFrame;
    int img_index = 0;
    while (images.read(frame)) {
        //// Preprocess image
        cvtColor(frame, myFrame, COLOR_BGR2GRAY);
        Mat pre = preprocessImage(myFrame);
edit flag offensive delete link more
0

answered 2019-10-23 20:58:19 -0600

fabianc20 gravatar image

updated 2019-10-23 21:01:41 -0600

supra56 gravatar image

The function that calls removeLitght, must past a {360,1} Step value -in this case. Use cvtColor -which is the video equivalent of converTo. In this case BGR->Gray made the videoCapture frame fit the size of the Mat imread image.

code:

Mat frame, myFrame; 
int img_index = 0; 
while (images.read(frame)) { 
// Preprocess image 
cvtColor(frame, myFrame, COLOR_BGR2GRAY); 
Mat pre = preprocessImage(myFrame);
.
.
....}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-10-20 17:09:13 -0600

Seen: 1,094 times

Last updated: Oct 23 '19