5/06/2015

OpenCV300 rc1 - VideoCapture, imread example

This is Video capture example in ver. opencv 3.0 rc1.

In 3.0, location of functions are little changed.
In case of VideoCapture, we should include opencv_videoio300.lib.

So note to this source code for easy coding access.


#include < iostream>
#include < opencv2\opencv.hpp>
#include < opencv2\videoio.hpp>
#include < opencv2\highgui.hpp>

#ifdef _DEBUG           
#pragma comment(lib, "opencv_core300d.lib")   
#pragma comment(lib, "opencv_highgui300d.lib")
#pragma comment(lib, "opencv_videoio300d.lib")
#else   
#pragma comment(lib, "opencv_core300.lib")   
#pragma comment(lib, "opencv_highgui300.lib")
#pragma comment(lib, "opencv_videoio300.lib")
#endif    

using namespace std;
using namespace cv;
void main()
{
 
 Mat test;
 cv::VideoCapture cap("M:\\____videoSample____\\posco\\cartype1.avi");//0); 
 namedWindow("t");
 while(1)
 {
  cap >> test;
  if( test.empty() )
   break;

  imshow("t", test);

  if( waitKey(10) > 0)
   break;
 }
}



----

This is source code of using "imread" function. (need opencv_imgcodecs300.lib )

#include < iostream>
#include < opencv2\opencv.hpp>
#include < opencv2\highgui.hpp>
#include < opencv2\imgcodecs.hpp>

#ifdef _DEBUG           
#pragma comment(lib, "opencv_core300d.lib")   
#pragma comment(lib, "opencv_highgui300d.lib")
#pragma comment(lib, "opencv_imgcodecs300d.lib")
#else   
#pragma comment(lib, "opencv_core300.lib")   
#pragma comment(lib, "opencv_highgui300.lib")
#pragma comment(lib, "opencv_imgcodecs300.lib")
#endif    

using namespace std;
using namespace cv;
void main()
{
 
 Mat test;
 test = imread("M:\\____videoSample____\\torso\\Positive1.png");

 namedWindow("t");
 imshow("t", test);
 waitKey(0);

}





QT + OpenCV error : C1083 opencv2/opencv.hpp no such file or directory

In Qt, setting of "include and lib path" is configured in the .pro file.

For example :

INCLUDEPATH += C:\opencv300rc1\opencv\build\include
LIBS += C:\opencv300rc1\MyBuild\lib\Debug

But in my case, I can not find the reason of error "C1083 opencv.hpp no such file or directory..."

I tried various attempts, but I don't know why error occur.
But I found the way of to avoid the error.
That is using build setting tab (ctrl + 5).
In build environment, add opencv path INCLUDE and LIB.



I solved the problem in this way.
Please note.











Creating dynamic link library including OpenCV(on MS Visual studio)


The method to make dynamic link library is introduced in here.
https://msdn.microsoft.com/en-us//library/ms235636.aspx

This introduction is similar with this.
But if you refer both, you will be more helpful.

And see the this youtube video.
This video is also very useful.
https://www.youtube.com/watch?v=yEqRyQhhto8


firstly, make dll project in VS tool. like this->



And add new class.

And set opencv include and lib path setting.


Now coding your opencv application class.
see the sample code
In here, please note OPENCVDLL_API keyword.
OPENCVDLL_API is replaced dllexport or dllimport.
and It surely have to declare in front of exporting class name.


OpenCVDLL.h
...

#pragma once
// OpenCVDLL.h

#ifdef OPENCVDLL_EXPORTS
#define OPENCVDLL_API __declspec(dllexport) 
#else
#define OPENCVDLL_API __declspec(dllimport) 
#endif

#include < opencv2\opencv.hpp>

#ifdef _DEBUG            
#pragma comment(lib, "opencv_core249d.lib")    
#pragma comment(lib, "opencv_imgproc249d.lib")   //MAT processing    
#else    
#pragma comment(lib, "opencv_core249.lib")    
#pragma comment(lib, "opencv_imgproc249.lib")   
#endif  

namespace opencvdll_mare
{

 class OPENCVDLL_API OpenCVDLL
 {
 public:
  OpenCVDLL(void);
  ~OpenCVDLL(void);
  cv::Mat convert(cv::Mat& inMat);

 };
}


...

OpenCVDLL.cpp
...
#include "OpenCVDLL.h"

namespace opencvdll_mare
{

 OpenCVDLL::OpenCVDLL(void)
 {
 }


 OpenCVDLL::~OpenCVDLL(void)
 {
 }

 cv::Mat OpenCVDLL::convert(cv::Mat& inMat)
 {
  cv::Mat cMat;
  cv::Sobel(inMat, cMat, inMat.depth(), 1, 0);
  return cMat;
 }


}
...

You will get .dll, .lib and .h file after compile the OpenCVDLL project.

".dll, .lib" is build in Release or Debug folder. ".h" is just OpenCVDLL.h .


Now, let's use this dll in normal project.
Firstly, make console project and copy files of .dll, .lib, .h into new project folder.

We have to do lib setting. OpenCV setting is same with normal method.
Our dll setting is same with OpenCV.
But we don't need to set include folder path, because we copy header file in local project.



And coding your application.
Sample is like this.
loadOpenCVDLL/Source.cpp
...
#include < iostream>
using namespace std;

#include < opencv2\opencv.hpp>
#include "OpenCVDLL.h"

#ifdef _DEBUG            

#pragma comment(lib, "opencv_highgui249d.lib")    
#else
#pragma comment(lib, "opencv_highgui249.lib")    
#endif  


using namespace cv;

void main()
{
 

 Mat test = imread("AA.jpg");
 imshow("test",test);

 opencvdll_mare::OpenCVDLL cOpenCVDLL_test;
 Mat outmat = cOpenCVDLL_test.convert(test);
 imshow("dll test", outmat);

 waitKey(0);
}
...


After all, build and check the result.
My result is here.



5/04/2015

Java.lang.NullPointerException error, matlab install on the MAC

I met the this error message, after installing matlab on MAC.


But don't worry about that, this youtube video will solve.
Watch this.



Thank you.

Basic MOG2 example souce using opencv

Basic MOG2 source code.




...
#include < time.h>  
#include < opencv2\opencv.hpp>  
#include < opencv2\gpu\gpu.hpp>  
#include < string>  
#include < stdio.h>  


#ifdef _DEBUG          
#pragma comment(lib, "opencv_core249d.lib")  
#pragma comment(lib, "opencv_imgproc249d.lib")   //MAT processing  
#pragma comment(lib, "opencv_gpu249d.lib")  
#pragma comment(lib, "opencv_highgui249d.lib")  
#else  
#pragma comment(lib, "opencv_core249.lib")  
#pragma comment(lib, "opencv_imgproc249.lib")  
#pragma comment(lib, "opencv_gpu249.lib")  
#pragma comment(lib, "opencv_highgui249.lib")  
#endif     


#define RWIDTH 800  
#define RHEIGHT 600  

using namespace std;  
using namespace cv;  

int main()  
{  
 /////////////////////////////////////////////////////////////////////////  
 gpu::MOG2_GPU pMOG2_g(30);  
 pMOG2_g.history = 3000; //300;  
 pMOG2_g.varThreshold =64; //128; //64; //32;//;   
 pMOG2_g.bShadowDetection = true;  
 Mat Mog_Mask;  
 gpu::GpuMat Mog_Mask_g;  
 /////////////////////////////////////////////////////////////////////////  


 VideoCapture cap("M:\\____videoSample____\\blog\\video20.wmv");//0);  
 /////////////////////////////////////////////////////////////////////////  
 Mat o_frame;  
 gpu::GpuMat o_frame_gpu;  
 /////////////////////////////////////////////////////////////////////////  

 cap >> o_frame;  
 if( o_frame.empty() )  
  return 0;   
 
 /////////////////////////////////////////////////////////////////////////  


 unsigned long AAtime=0, BBtime=0;  

 //Mat rFrame;  
 Mat showMat_r_blur;  
 Mat showMat_r;  

 namedWindow("origin");
 namedWindow("mog_mask");

 while(1)  
 {  
  /////////////////////////////////////////////////////////////////////////  
  cap >> o_frame;  
  if( o_frame.empty() )  
   return 0;  


  o_frame_gpu.upload(o_frame);
  AAtime = getTickCount();
  
  //  
  pMOG2_g.operator()(o_frame_gpu, Mog_Mask_g,-1);  
  //
  Mog_Mask_g.download(Mog_Mask);

  BBtime = getTickCount();
  float pt = (BBtime - AAtime)/getTickFrequency();
  float fpt = 1/pt;
  printf("gpu %.4lf / %.4lf \n",  pt, fpt );


  
  o_frame_gpu.download(showMat_r);
  imshow("origin", showMat_r); 
  imshow("mog_mask", Mog_Mask);


  /////////////////////////////////////////////////////////////////////////  

  if( waitKey(10) > 0)  
   break;  
 }  

 return 0;  
}  

build opencv 3.0 + cuda 6.5 + QT 5.4 + tbb

These are cmake configuration for OpenCV rc1 + CUDA 6.5 + QT 5.4 + TBB 4.3








I thought it will help opencv building beginner.
I will help how to set path and what I should check.

And configuration result is here.



Now I am building on VS 2012... I hope to build with no error.. ^^

Refer to this page, these are my result of building opencv in waste of time.