Archivo de la etiqueta: opencv

OpenCV 2.1 on NetBeans on Windows

OpenCV

NetBeans

First of all, try no to use Windows.

1. Make sure you got the following installed

  • C:\OpenCV2.1
  • C:\MinGW
  • C:\msys

2. Right click on your project and click in Properties and complete the following:

Build » C++ Compiler
   » Include Directories » C:/OpenCV2.1/include/opencv

Build » C++ Compiler » Include Directories » C:/OpenCV2.1/include/openc

   » Linker
      » Additional Library Directories » C:/OpenCV2.1/lib
      » Libraries » cv210.dll, cvaux210.dll,
                    cxcore210.dll, highgui210.dll

Build » Linker

3. Build your project.

Executable (*.exe) file will be generated and located in your project directory on the following path: dist/Debug/MinGW-Windows/

Use this simple code to test your recently set environment:

#include "highgui.h"

int main(int argc, char** argv){
   IplImage* img = cvLoadImage(argv[1]);
   cvNamedWindow("ImgViewer", CV_WINDOW_AUTOSIZE);
   cvShowImage("ImgViewer", img);
   cvWaitKey(0);
   cvReleaseImage(&img);
   cvDestroyWindow("ImgViewer");
}
Anuncios

OpenCV » Update the Slider Position

OpenCV: Open Computer Vision Library

I am currently making some research on OpenCV to accomplish some knowledge necessary for working on Computer Vision and lately on Gesture Recognition.

The book i am reading now is Learning OpenCV (Computer Vision with the OpenCV Library) by Gary Bradski & Adrian Kaehler

On Chapter 2: Introduction to OpenCV there are some samples. Second Program is about Playing AVI Video with OpenCV. And Third Program is about move around quickly within the video. We can read these on page 21:

* This code does not update the slider position as the video plays; we leave that as an exercise for the reader.
Also note that some mpeg encodings do not allow you to move backward in the video.

That exercise is relative simple so this is the code i propose:

#include "cv.h"
#include "highgui.h"

int			g_slider_position = 0;
CvCapture*	g_capture			= NULL;

void onTrackbarSlide(int pos) {
   cvSetCaptureProperty(
      g_capture,
      CV_CAP_PROP_POS_FRAMES,
      pos
   );
}

int main (int argc, char** argv) {
   cvNamedWindow("AviPlayer", CV_WINDOW_AUTOSIZE);
   g_capture = cvCreateFileCapture(argv[1]);
   int frames = (int) cvGetCaptureProperty(
      g_capture,
      CV_CAP_PROP_FRAME_COUNT
   );
   if(frames!=0){
      cvCreateTrackbar(
         "Position",
         "AviPlayer",
         &g_slider_position,
         frames,
         onTrackbarSlide
      );
   }
   IplImage* frame;
   while(1){
      frame = cvQueryFrame(g_capture);
      if(!frame) break;
      
		double newpos = cvGetCaptureProperty(g_capture, CV_CAP_PROP_POS_FRAMES);
      cvSetTrackbarPos("Position", "AviPlayer", newpos);
      
      cvShowImage("AviPlayer", frame);
      char c = cvWaitKey(33);
      if ( c == 27 ) break;
   }
   cvReleaseCapture(&g_capture);
   cvDestroyWindow("AviPlayer");
   return(0);
}

References:
cvGetCaptureProperty: Gets video capturing properties