Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Do we need to optimize matrix operation of cv::Mat?

clean and easy to read, but this kind of operation may generate two temporary objects

foreground_current = (frame_current_ - (1 - Beta_) * background_current_) / Beta_; //#1

Hard to read and verbose

//can't alter the value of background_current
background_current_.copyTo(temp_);
temp_ *= 1 - Beta_; //can't use (Beta_ - 1) since it is negative
frame_current_.copyTo(foreground_current_);
foreground_current_ -= temp_;
foreground_mask_ /= Beta_;

What I want to ask is, do openCV provide some optimization for operator overloading? With the help of expression template, it is possible to eliminate the temporary objects of #1 do openCV2 support this kind of optimization?Thanks

Do we need to optimize matrix operation of cv::Mat?

clean and easy to read, but this kind of operation may generate two temporary objects

foreground_current = (frame_current_ - (1 - Beta_) * background_current_) / Beta_; //#1

Hard to read and verbose

//can't alter the value of background_current
background_current_.copyTo(temp_);
temp_ *= 1 - Beta_; //can't use (Beta_ - 1) since it is negative
frame_current_.copyTo(foreground_current_);
foreground_current_ -= temp_;
foreground_mask_ /= Beta_;

What I want to ask is, do openCV provide some optimization for operator overloading? With the help of expression template, it is possible to eliminate the temporary objects of #1 do #1. Do openCV2 support this kind of optimization?Thanks

Do we need to optimize matrix operation of cv::Mat?

clean and easy to read, but this kind of operation may generate two temporary objects

foreground_current = (frame_current_ - (1 - Beta_) * background_current_) / Beta_; //#1

Hard to read and verbose

//can't alter the value of background_current
background_current_.copyTo(temp_);
temp_ *= 1 - Beta_; //can't use (Beta_ - 1) since it is negative
frame_current_.copyTo(foreground_current_);
foreground_current_ -= temp_;
foreground_mask_ /= Beta_;

or write a for loop for it?

//same as for loop
OCV::transform_channels<uchar>(frame_current_, background_current_, foreground_current_, [=](uchar fr, uchar bg)
    {
        return fr - (1 - Beta_) * bg;
    });

What I want to ask is, do openCV provide some optimization for operator overloading? With the help of expression template, it is possible to eliminate the temporary objects of #1. Do openCV2 support this kind of optimization?Thanks

Do we need to optimize matrix operation of cv::Mat?

clean and easy to read, but this kind of operation may generate two temporary objects

foreground_current = (frame_current_ - (1 - Beta_) * background_current_) / Beta_; //#1

Hard to read and verbose

//can't alter the value of background_current
background_current_.copyTo(temp_);
temp_ *= 1 - Beta_; //can't use (Beta_ - 1) since it is negative
frame_current_.copyTo(foreground_current_);
foreground_current_ -= temp_;
foreground_mask_ /= Beta_;

or write a for loop for it?

//same as for loop
OCV::transform_channels<uchar>(frame_current_, background_current_, foreground_current_, [=](uchar fr, uchar bg)
    {
        return fr cv::saturate_cast<Type>((fr - (1 - Beta_) * bg;
bg) / Beta_);
    });

What I want to ask is, do openCV provide some optimization for operator overloading? With the help of expression template, it is possible to eliminate the temporary objects of #1. Do openCV2 support this kind of optimization?Thanks

Do we need to optimize matrix operation of cv::Mat?

clean and easy to read, but this kind of operation may generate two temporary objects

foreground_current = (frame_current_ - (1 - Beta_) * background_current_) / Beta_; //#1

Hard to read and verbose

//can't alter the value of background_current
background_current_.copyTo(temp_);
temp_ *= 1 - Beta_; //can't use (Beta_ - 1) since it is negative
frame_current_.copyTo(foreground_current_);
foreground_current_ -= temp_;
foreground_mask_ /= Beta_;

or write a for loop for it?

//same as for loop
OCV::transform_channels<uchar>(frame_current_, background_current_, foreground_current_, [=](uchar fr, uchar bg)
    {
        return cv::saturate_cast<Type>((fr - (1 - Beta_) * bg) / Beta_);
    });

What I want to ask is, do openCV provide some optimization for operator overloading? With the help of expression template, it is possible to eliminate the temporary objects of #1. Do openCV2 support this kind of optimization?Thanks