OpenCV 如何在图像为 ==` 时获取 bool true,如果不是则获取 false?
所以我们尝试这样的代码:
cv::Mat m1, m2;
cv::VideoCapture cap(0);
do {
cap >> m1;
cap >> m2;
} while(cv::norm(m1,m2)==0);
frames+=2;
//...
但它似乎不起作用。那么相机采集的帧数据内容是否相同如何获取bool呢?
So we try code like:
cv::Mat m1, m2;
cv::VideoCapture cap(0);
do {
cap >> m1;
cap >> m2;
} while(cv::norm(m1,m2)==0);
frames+=2;
//...
but it seems not to work. So how to get bool if frames data contents captured from camera are same or not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的方法失败了,因为在真实的相机视频流中(从您的代码中我看到您从相机捕获),由于噪声、照明变化、相机运动小等原因,每两帧不相等。您可以将检查更改为
: epsilon 是一些无符号数字,您可以自己找到它(这取决于您的标准)。这是非常快速且简单的解决方案。
查看 karlphillip 的链接以获得更有效的解决方案。
Your method fails because in real camera videostream (from your code I see that you capture from camera) every two frames are not equal because of noise, changing illumination, small camera motion etc. You can change your check to this:
Where
epsilon
is some unsigned number which you can find by yourself (it depends on your criteria). This is very fast and simple solution.Look at karlphillip's link to get more efficient solution.
谷歌“opencv区别”=>
http://andybest.net/2009/02/processing -opencv-tutorial-2-bubbles/
http://ubaa.net/shared/processing/opencv/opencv_absdiff.html
http://createdigitalmotion.com/2009/ 02/processing-tutorials-getting-started-with-video-processing-via-opencv/
opencv.absDiff ()
等Google "opencv difference" =>
http://andybest.net/2009/02/processing-opencv-tutorial-2-bubbles/
http://ubaa.net/shared/processing/opencv/opencv_absdiff.html
http://createdigitalmotion.com/2009/02/processing-tutorials-getting-started-with-video-processing-via-opencv/
opencv.absDiff ()
, etc据我所知,OpenCV 中没有这样的功能,但它很容易实现。任何返回元素之和的函数都将是错误的,因为一个像素中的差异可以通过其他像素中的差异来补偿。保证正确性的唯一方法是逐像素检查。这是一个简单的例子:
我没有检查代码,所以,小心地执行“ctrl+c”。
There is no such a function I'm aware off in OpenCV, but it can easily be implemented. Any function that return's a sum of the elements will be wrong, because differences in one pixel can be compensated by differences in other pixels. The only way to guarantee correctness is by doing a pixel by pixel check. Here is a simple example:
I didn't checked the code, so, be careful just doing a 'ctrl+c'.