ammit2 / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

Dense Optical in JavaCV (DualTVL1) #468

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
public void TestOF()
{
IplImage pFrame = cvLoadImage("/sdcard//DCIM/Camera/Frame-1.jpg");
IplImage cFrame = cvLoadImage("/sdcard//DCIM/Camera/Frame-2.jpg");
IplImage pGray = cvCreateImage(cvGetSize(pFrame),IPL_DEPTH_8U,1);
IplImage cGray = cvCreateImage(cvGetSize(cFrame),IPL_DEPTH_8U,1);

cvConvertImage(pFrame, pGray, IPL_DEPTH_32F);
cvConvertImage(cFrame, cGray, IPL_DEPTH_32F);
IplImage Optical_Flow  = cvCreateImage( cvGetSize(pGray), IPL_DEPTH_32F, 2 );

DenseOpticalFlow tvl1 = createOptFlow_DualTVL1();
tvl1.calc(pGray, cGray, Optical_Flow);

FloatBuffer buffer = Optical_Flow.getFloatBuffer();
CvMat OF  = cvCreateMat( pGray.height(),pGray.width(), CV_32FC1);

int pixelVelocity =0;
int xVelocity = 0;
int yVelocity = 0;
int bufferIndex = 0;

for(int y =0; y< pGray.height(); y++)
 {
   for(int x = 0; x < pGray.width() ;x++)
   {
      xVelocity = (int)buffer.get(bufferIndex);
      yVelocity = (int)buffer.get(bufferIndex+1);
      pixelVelocity = (int)Math.sqrt((double)(xVelocity*xVelocity +         yVelocity*yVelocity));
      OF.put(y, x, pixelVelocity);
   }
 }
IplImage temp = OF.asIplImage();
cvSaveImage("/sdcard//DCIM/Camera/OF.jpg",temp);
}

This code will calculate the optical flow for every pixel using 
DenseOpticalFlow between two images (Frame-1 & Frame-2) and put the velocity of 
every pixel to anther image (OF) in their coordinate.

Original issue reported on code.google.com by dawit.ge...@gmail.com on 2 May 2014 at 7:29

GoogleCodeExporter commented 8 years ago
Thanks! I've adapted the code for the new version of JavaCV here:
https://github.com/bytedeco/javacv/commit/40ab2083ce7e75a8cc37bae5b69762391af5f4
48

Google Code doesn't come with an interface that lets anyone add files to the 
repository, but GitHub does, so check it out! Thanks

Original comment by samuel.a...@gmail.com on 3 May 2014 at 2:11

GoogleCodeExporter commented 8 years ago
Sample included in JavaCV 0.9. Thank you for your contribution!

Original comment by samuel.a...@gmail.com on 30 Jul 2014 at 11:15