how to subtract one frame from another using opencv in android

泄露秘密 提交于 2019-12-05 20:05:10

If you just subtract one frame from the other, you are going to end up with an image that only contains the areas where the second frame has higher values than the first frame.

To get differences, you need to use absdiff:

absdiff(imgToProcess1, imgToProcess2, imgToProcess);

This will give you a matrix of the actual differences, but if you want a mask of the areas of difference, you can apply a threshold to the result:

Mat mask(imgToProcess.rows, imgToProcess.cols, CV_8U);
cvtColor(imgToProcess, mask, CV_RGB2GRAY, 1); //your conversion specifier may vary
threshold(mask, mask, 0, 255, CV_THRESH_BINARY);

The minimum threshold value (0 above) can be adjusted. If you are using JPEG images, then you may need to increase it a bit to account for encoding noise.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!