12/29/2016

opencv mouse event example code


...
void CallBackFunc(int event, int x, int y, int flags, void* userdata)
{
 if (event == EVENT_LBUTTONDOWN)
 {
  printf("lLBUTTONDOWN down %d, %d \n", x, y);

  //circle( (*(Mat*)userdata), Point(x, y), 2, CV_RGB(255, 0, 0), 3);
 }
 else if (event == EVENT_RBUTTONDOWN)
 {
  printf("RBUTTONDOWN down %d, %d \n", x, y);
 }
 else if (event == EVENT_MBUTTONDOWN)
 {
  printf("MBUTTONDOWN down %d, %d \n", x, y);
 }
 else if (event == EVENT_MOUSEMOVE)
 {
  printf("move %d, %d \n", x, y);
 }
 
 //imshow("img", (*(Mat*)userdata)); //show
}


int main(int, char)
{
 namedWindow("img", 0);
 
 Mat img = imread("gh.jpg");
 

 setMouseCallback("img", CallBackFunc, &img);

 imshow("img", img); //show
 waitKey(0);


 /*
 while (1)
 {
  imshow("img", img); //show
  if (waitKey(10) > 0)
   break;
 }
 */

 destroyAllWindows();

 return 0;
}

...



findContours, drawContours example code

The code is various example code for drawing contours.


...
namedWindow("show1", 0);
 namedWindow("threshold", 0);
 namedWindow("contours", 0);

 Mat img;
 img = imread("pattern.jpg");

 cvtColor(img, img, CV_RGB2GRAY);
 
 imshow("show1", img);


 threshold(img, img, 128, 255, CV_THRESH_BINARY);
 imshow("threshold", img);


 Mat dst = Mat::zeros(img.rows, img.cols, CV_8UC3);
 
 vector< vector< Point> > contours;
 vector< Vec4i> hierarchy;

 findContours(img.clone(), contours, hierarchy,
  RETR_CCOMP, CHAIN_APPROX_SIMPLE);

 
 //ex 1)
 drawContours(dst, contours, -1, CV_RGB(255,0,0), 1, 8, hierarchy);

 
 // iterate through all the top-level contours,
 // draw each connected component with its own random color
 //ex 2)
 int idx = 0;
 for (; idx >= 0; idx = hierarchy[idx][0])
 {
  Scalar color(rand() & 255, rand() & 255, rand() & 255);
  //drawContours(dst, contours, idx, color, FILLED, 8, hierarchy);
  drawContours(dst, contours, idx, color, 1, 8, hierarchy);
 }
 


 //ex3
 for (int i = 0; i < contours.size(); ++i)
 {
  
  for (int j = 0; j < contours[i].size() - 1; ++j)
  {
   line(dst, contours[i][j], contours[i][j + 1], CV_RGB(255, 0, 0), 1);
  }
  line(dst, contours[i][0], contours[i][contours[i].size()-1], CV_RGB(255, 0, 0), 1);
  
 }

 //ex4
 for (int i = 0; i < contours.size(); ++i)
 {

  Scalar color(rand() & 255, rand() & 255, rand() & 255);
  //drawContours(dst, contours, idx, color, FILLED, 8, hierarchy);
  drawContours(dst, contours, i, color, 1, 8, hierarchy);
 }
 

 //imshow("show3", img);
 imshow("contours", dst);


...



12/28/2016

File exist check code



bool fileExists(const char* path)
{
  FILE* file;
  bool exists;

  file = fileOpen(path, "r");
  exists = file != 0;

  if (file)
    fclose(file);

  return exists;
}

FILE* fileOpen(const char* path, const char* mode)
{
  char path_[PATH_MAX];

  assert(path);

  resolvePath(path_, sizeof(path_), path);

  FILE* fp;
  fopen_s(&fp, path_, mode);
  return fp;
}

explanation of _CRT_SECURE_NO_WARNINGS, VO_MSE_FUNC_THROUGH_POINTERS option in Visual Studio

I was then able to build your project proceeding as follows:
-in the Preprocessor Definitions, you did not add both compiler options _CRT_SECURE_NO_WARNINGS and VO_MSE_FUNC_THROUGH_POINTERS
_CRT_SECURE_NO_WARNINGS is necessary to use the strcpy function
VO_MSE_FUNC_THROUGH_POINTERS is needed to get the pointers to the exported functions of the libraries
-Also, as your code is c++, you need to add extern "C" to "voEngine engine = NULL;" and "#include "
// global engine (for the sake of readability)
extern "C" voEngine engine = NULL;

// common utility functions
extern "C" {
#include
}