What is the meaning of following code line in opencv?

前端 未结 2 636
盖世英雄少女心
盖世英雄少女心 2021-02-06 12:44

What does this code line means and how can I convert this code into javacv?

gray = Scalar::all(255);

This is whole code which related to this

2条回答
  •  礼貌的吻别
    2021-02-06 13:35

    The highlighted code line sets gray to 255. It is one of the methods avaliable in OpenCV to set a matrix to a value.

    Other ways to do it are:

    gray.setTo(255); // prior to 2.3.1 it was a buggy on multichannel images
    gray = 255; // prior to 2.3.1 it was a buggy on multichannel images
    
    gray.setTo(Scalar::all(255)); // it works regardless the OpenCV version.
    

    But I think the question is why this source line after findfContours...

    According to the docs, findContours modifies the image it is working on (it extracts a contour, deteles it, then proceed to the next one, until there are no more contours). The result is a garbage image (probably black).

    So, the set-to-255 line clears it up for some other use.

    The Mat::setTo() method should also be available in JavaCV, so you should not have problems converting it to Java

提交回复
热议问题