如何从另一个使用OpenCV的Andr​​oid中减去一帧 [英] how to subtract one frame from another using opencv in android

查看:133
本文介绍了如何从另一个使用OpenCV的Andr​​oid中减去一帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个视频帧,我想减去其他一帧,找出差异,但我不知道如何着手。我试图将我的位图帧到垫子,然后减去他们,但它不工作。我使用OpenCV的2.4.3垫的功能。有谁能够告诉我该怎么做。如果可能的话用code片段解释。

我想这样的事情

 位图myBitmap1 = BitmapFactory.de codeFILE(到/ mnt / SD卡/帧/ mpgFrames / image001.jpg);
    位图myBitmap2 = BitmapFactory.de codeFILE(到/ mnt / SD卡/帧/ mpgFrames / image002.jpg);

    INT宽度= myBitmap1.getWidth();
    INT高= myBitmap1.getHeight();

    垫imgToProcess1 =新垫(高度,宽度,CvType.CV_8UC4);
    垫imgToProcess2 =新垫(高度,宽度,CvType.CV_8UC4);
    垫imgToProcess =新垫(高度,宽度,CvType.CV_8UC4);

    Utils.bitmapToMat(myBitmap1,imgToProcess1);
    Utils.bitmapToMat(myBitmap2,imgToProcess1);
    imgToProcess = imgToProcess1-imgToProcess2;
 

解决方案

如果你只是减去一帧从其他的,你要结束了,只包含其中第二架具有比更高的值的区域的图像第一帧。

要获得的区别的,你需要使用 absdiff

  absdiff(imgToProcess1,imgToProcess2,imgToProcess);
 

这会给你的实际差异矩阵,但如果你想的差的地区面膜,你可以申请一个阈值的结果:

 垫面膜(imgToProcess.rows,imgToProcess.cols,CV_8U);
cvtColor(imgToProcess,口罩,CV_RGB2GRAY,1); //你的转换符可能会有所不同
阈值(掩模,掩模,0,255,CV_THRESH_BINARY);
 

最小阈值( 0 以上)可以调整。如果你正在使用的JPEG图像,那么你可能需要增加它有点占编码噪点。

i am working on frames of a video and i want to subtract one frame from other to find out the difference but i dont know how to proceed. i tried converting my bitmap frames into mat and then subtracting them but its not working. i am using opencv 2.4.3 for mat function. can anybody tell me how to do that. if possible explain with code snippets.

i tried something like this

     Bitmap myBitmap1 = BitmapFactory.decodeFile("/mnt/sdcard/Frames/mpgFrames/image001.jpg");  
    Bitmap myBitmap2 = BitmapFactory.decodeFile("/mnt/sdcard/Frames/mpgFrames/image002.jpg");  

    int width = myBitmap1.getWidth();
    int height = myBitmap1.getHeight();

    Mat  imgToProcess1 = new Mat(height, width, CvType.CV_8UC4);
    Mat  imgToProcess2 = new Mat(height, width, CvType.CV_8UC4);
    Mat  imgToProcess = new Mat(height, width, CvType.CV_8UC4);

    Utils.bitmapToMat(myBitmap1, imgToProcess1); 
    Utils.bitmapToMat(myBitmap2, imgToProcess1);        
    imgToProcess = imgToProcess1-imgToProcess2;

解决方案

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.

这篇关于如何从另一个使用OpenCV的Andr​​oid中减去一帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆