SOL9 Sample: VideoCapture

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * VideoCapture.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


//2017/07/25
//This is a simple example to capture videoDevice, and to display the capturued frames 
//to original imageview and blurred image view based on cv::boxFiter.

#define _CONSOLE_

#include <sol/ModuleFileName.h>
#include <sol/DropFiles.h>
#include <sol/LabeledTrackBar.h>
#include <sol/FileDialog.h>
#include <sol/opencv/OpenCVVideoApplication.h>
#include <sol/opencv/OpenCVVideoCaptureView.h>
#include <sol/opencv/OpenCVNamedWindow.h>

namespace SOL {

class MainView :public OpenCVVideoCaptureView {

private:
  ////////////////////////////////////////////////////////////////////////////////////////
  //Inner class starts.
  class VideoImageView :public OpenCVNamedWindow {
  private:
    cv::Mat frame;
    
  public:    
    void display()
    {
      show(frame);
    }
    
  public:
    VideoImageView(View* parent, const char* name, Args& args)
    :OpenCVNamedWindow(parent, name, args)
    {
    }

    void setImage(cv::Mat& image)
    {
      frame = image;
    }
  };
  
  //Inner class ends.
  ////////////////////////////////////////////////////////////////////////////////////////
      
  SmartPtr<VideoImageView>     videoImage;

  void resize(int w, int h)
  {
    if (videoImage) {
      videoImage   -> reshape(0,  0,  w,   h);
    }
  }

  void confirm(Action& action)
  {
    int rc = MessageBox(NULL, "Are you sure to close this window?", "Confirmation", 
                MB_OKCANCEL|MB_ICONEXCLAMATION);
    if (rc == IDOK) {
      exit(action);
    }
  }
  
public:
  MainView(OpenCVApplication& applet, const char* name, Args& args)
  :OpenCVVideoCaptureView(applet, name, args)
  {
    try {
      Args ar;
      videoImage = new VideoImageView(this, "cvwindow1", ar); 
      
      addCallback(XmNmenuCallback, IDM_EXIT, this,
          (Callback)&MainView::confirm, NULL);
     
      //setImageViewSize(videoImage);  
      
    } catch (Exception& ex) {
      caught(ex);
    }
  }

  ~MainView()
  {
  }
 
  //This method will be called from a OpenCVTimerThread::run.
  virtual void render()
  {
    cv::Mat frame;
    if (readVideoFrame(frame)) {
      if (!frame.empty() && videoImage) {
        videoImage -> setImage(frame);
        videoImage -> display();
      }
    }
  }
};
}


void main(int argc, char** argv) 
{
  try {
    ModuleFileName module(argv[0]);
    
    const char*  name = module.getAppName();
  
    OpenCVVideoApplication applet(name, argc, argv);

    Args args;
    args.set(XmNwidth,     620);
    args.set(XmNheight,    440);
    args.set(XmNvideoDeviceIndex, 0);
    args.set(XmNcaptureAutoStart, true);
    MainView view(applet, name, args);
    view.realize();

    applet.run(view);
    
  } catch (SOL::Exception& ex) {
    caught(ex);
  }
}


Last modified: 2 Dec. 2017

Copyright (c) 2017 Antillia.com ALL RIGHTS RESERVED.