Skip to content

Instantly share code, notes, and snippets.

@minhoolee
Last active November 2, 2015 19:16
Show Gist options
  • Save minhoolee/ba16ec7266c0ad4c6319 to your computer and use it in GitHub Desktop.
Save minhoolee/ba16ec7266c0ad4c6319 to your computer and use it in GitHub Desktop.
MVRT Vision Trainings
int add(int x, int y)
{
return x + y;
}
// This is start of the header guard
// ADD_HPP can be any unique name
// By convention, we use the name of the header file
#ifndef ADD_HPP
#define ADD_HPP
// This is the content of the .hpp file, which is where the declarations go
int add(int x, int y); // function prototype for add.hpp -- don't forget the semicolon!
// This is the end of the header guard
// Recall, expressions beginning with the "#" sign are preprocessors
#endif
#include "opencv2/opencv.hpp"
using namespace cv;
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat edges;
namedWindow("edges",1);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, COLOR_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
#include <iostream>
// Note that custom header files are in quotation marks by convention,
// but standard libraries such as iostream are in side angled brackets
#include "add.hpp"
int main()
{
using namespace std;
cout << "The sum of 3 and 4 is " << add(3, 4) << endl;
return 0;
}
#include "opencv2/opencv.hpp"
using namespace cv;
void exampleMethod (cv::Mat& frame);
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat edges;
namedWindow("edges",1);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, COLOR_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
// Pass frame as alias instead of by instance to save memory
void exampleMethod (cv::Mat& frame)
{
// Do stuff with frame now
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment