当用于带孔的区域时,cv :: floodFill会崩溃

时间:2016-02-12 16:00:49

标签: c++ opencv

以下最低限度示例似乎陷入无休止的循环中。它会运行几分钟,然后最终崩溃std::bad_alloc(OpenCV 3.0)。

int main()
{
    cv::Mat img( cv::Size( 128, 128 ), CV_8UC1, cv::Scalar( 128 ) );
    cv::Mat mask( cv::Size( 130, 130 ), CV_8UC1, cv::Scalar( 0 ) );
    cv::rectangle( img, cv::Rect( 32, 32, 64, 64 ), cv::Scalar( 0 ), CV_FILLED );
    cv::rectangle( img, cv::Rect( 64, 64, 16, 16 ), cv::Scalar( 255 ), CV_FILLED ); // draw white hole in black region
    cv::floodFill( img, mask, cv::Point( 42, 42 ),
        cv::Scalar( 255 ), 0,
        cv::Scalar( 20 ), cv::Scalar( 30 ),
        cv::FLOODFILL_MASK_ONLY );
}

它试图填充黑色区域。

enter image description here

如果我移除了白洞,它会像预期的那样工作。我用非法参数调用函数,还是这个bug?

1 个答案:

答案 0 :(得分:2)

The import multiprocessing as mp import psutil def spawn(): procs = list() n_cpus = psutil.cpu_count() for cpu in range(n_cpus): affinity = [cpu] d = dict(affinity=affinity) p = mp.Process(target=run_child, kwargs=d) p.start() procs.append(p) for p in procs: p.join() print('joined') def run_child(affinity): proc = psutil.Process() # get self pid print('PID: {pid}'.format(pid=proc.pid)) aff = proc.cpu_affinity() print('Affinity before: {aff}'.format(aff=aff)) proc.cpu_affinity(affinity) aff = proc.cpu_affinity() print('Affinity after: {aff}'.format(aff=aff)) if __name__ == '__main__': spawn() value you pass is not strictly legal -- you should include the values for the lower bits as well (for connectivity and fill value, as mentioned in the opencv docs):

flags