OpenCV: Background Subtraction When Suddenly Changing Light

I am working on subtracting a backgroun with a sudden change in light. Is there any code example or a way to do this efficiently in OpenCV or IPP? I read video frames, so the runtime should be very fast. Thanks in advance.

+5
source share
3 answers

you need to first develop some kind of normalization method where both frames (one with low light and the other with lots of light) will be normalized and should contain values ​​that are very close.

Unfortunately, I had the same problem, and I could not completely solve it, but one way to solve this problem is to perform histogram alignment .

.

+4

, . . , RGB (). , , . RGB , BackgroundSubtractorMOG2.

. , , 2 4 .

void makeIlluminationInvariantRGB(const cv::Mat& frame, cv::Mat& result) {
    frame.copyTo(result);
    uint8_t* pixelPtr = (uint8_t*)result.data;
    int cn = result.channels();
    int bitshift = 3;

    for(int row = 0; row < result.rows; row++)
    {
        for(int col = 0; col < result.cols; col++)
        {
            pixelPtr[row*result.cols*cn + col*cn + 0] = pixelPtr[row*result.cols*cn + col*cn + 0] >> bitshift;

            pixelPtr[row*result.cols*cn + col*cn + 1] = pixelPtr[row*result.cols*cn + col*cn + 1] >> bitshift;

            pixelPtr[row*result.cols*cn + col*cn + 2] = pixelPtr[row*result.cols*cn + col*cn + 2] >> bitshift;
        }
    }
}

, .

0

, meanStdDev . , reset .

0

All Articles