Skip to content

Instantly share code, notes, and snippets.

@danfal
Created July 27, 2015 17:49
Show Gist options
  • Save danfal/1b4f15374781ecf43c54 to your computer and use it in GitHub Desktop.
Save danfal/1b4f15374781ecf43c54 to your computer and use it in GitHub Desktop.
/*
==============================================================================
This file was auto-generated by the Introjucer!
It contains the basic startup code for a Juce application.
==============================================================================
*/
#include <opencv2/opencv.hpp>
#include "../JuceLibraryCode/JuceHeader.h"
#include "MainComponent.h"
//==============================================================================
class nicesauceApplication : public JUCEApplication
{
public:
//==============================================================================
nicesauceApplication() {}
const String getApplicationName() override { return ProjectInfo::projectName; }
const String getApplicationVersion() override { return ProjectInfo::versionString; }
bool moreThanOneInstanceAllowed() override { return true; }
//==============================================================================
void initialise (const String& commandLine) override
{
// This method is where you should put your application's initialisation code..
cv::VideoCapture cap(1); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return;
cv::Mat edges;
//cv::namedWindow("edges",1);
// Setup output video
cv::VideoWriter output_cap("hej.avi",
CV_FOURCC('M','J','P','G'),
30,
cv::Size(cap.get(CV_CAP_PROP_FRAME_WIDTH),
cap.get(CV_CAP_PROP_FRAME_HEIGHT)));
if (!output_cap.isOpened())
{
std::cout << "!!! Output video could not be opened" << std::endl;
return;
}
for(;;)
{
cv::Mat frame;
cap >> frame; // get a new frame from camera
cv::cvtColor(frame, edges, CV_BGR2GRAY);
cv::GaussianBlur(edges, edges, cv::Size(7,7), 1.5, 1.5);
cv::Canny(edges, edges, 0, 30, 3);
cv::imshow("edges", edges);
cv::cvtColor(edges, edges, CV_GRAY2RGB);
output_cap.write(edges);
if(cv::waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
mainWindow = new MainWindow (getApplicationName());
}
void shutdown() override
{
// Add your application's shutdown code here..
mainWindow = nullptr; // (deletes our window)
}
//==============================================================================
void systemRequestedQuit() override
{
// This is called when the app is being asked to quit: you can ignore this
// request and let the app carry on running, or call quit() to allow the app to close.
quit();
}
void anotherInstanceStarted (const String& commandLine) override
{
// When another instance of the app is launched while this one is running,
// this method is invoked, and the commandLine parameter tells you what
// the other instance's command-line arguments were.
}
//==============================================================================
/*
This class implements the desktop window that contains an instance of
our MainContentComponent class.
*/
class MainWindow : public DocumentWindow
{
public:
MainWindow (String name) : DocumentWindow (name,
Colours::lightgrey,
DocumentWindow::allButtons)
{
setUsingNativeTitleBar (true);
setContentOwned (new MainContentComponent(), true);
centreWithSize (getWidth(), getHeight());
setVisible (true);
}
void closeButtonPressed() override
{
// This is called when the user tries to close this window. Here, we'll just
// ask the app to quit when this happens, but you can change this to do
// whatever you need.
JUCEApplication::getInstance()->systemRequestedQuit();
}
/* Note: Be careful if you override any DocumentWindow methods - the base
class uses a lot of them, so by overriding you might break its functionality.
It's best to do all your work in your content component instead, but if
you really have to override any DocumentWindow methods, make sure your
subclass also calls the superclass's method.
*/
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindow)
};
private:
ScopedPointer<MainWindow> mainWindow;
};
//==============================================================================
// This macro generates the main() routine that launches the app.
START_JUCE_APPLICATION (nicesauceApplication)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment