diff --git a/Examples/Plugins/org.mitk.example.gui.opencv/src/internal/SimpleOpenCVExample.cpp b/Examples/Plugins/org.mitk.example.gui.opencv/src/internal/SimpleOpenCVExample.cpp index 0380e45b2f..e6bfe23ad2 100644 --- a/Examples/Plugins/org.mitk.example.gui.opencv/src/internal/SimpleOpenCVExample.cpp +++ b/Examples/Plugins/org.mitk.example.gui.opencv/src/internal/SimpleOpenCVExample.cpp @@ -1,124 +1,143 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // Blueberry #include #include // Qmitk #include "SimpleOpenCVExample.h" // mitk image #include #include #include +#include +#include + const std::string SimpleOpenCVExample::VIEW_ID = "org.mitk.views.simpleopencvexample"; void SimpleOpenCVExample::SetFocus() {} void SimpleOpenCVExample::CreateQtPartControl(QWidget *parent) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi(parent); connect(m_Controls.m_StartGrabbing, SIGNAL(clicked()), this, SLOT(OnStartGrabbing())); connect(m_UpdateTimer, SIGNAL(timeout()), this, SLOT(OnUpdateImage())); } SimpleOpenCVExample::SimpleOpenCVExample() : m_running(false), m_UpdateTimer(new QTimer()) { } SimpleOpenCVExample::~SimpleOpenCVExample() {} void SimpleOpenCVExample::OnStartGrabbing() { if (!m_running) { m_running = true; m_Controls.m_StartGrabbing->setText("Stop Video Grabbing"); m_VideoCapture = new cv::VideoCapture(); // open the default camera m_VideoCapture->open(m_Controls.m_InputID->value()); if (!m_VideoCapture->isOpened()) {return;} // check if we succeeded if (m_Controls.m_enableResolution->isChecked()) { m_VideoCapture->set(CV_CAP_PROP_FRAME_WIDTH, m_Controls.m_resX->value()); m_VideoCapture->set(CV_CAP_PROP_FRAME_HEIGHT, m_Controls.m_resY->value()); } + cv::VideoWriter outputVideo1; + cv::VideoWriter outputVideo2; + if (m_Controls.m_writeFile->isChecked()) + { + cv::Size S = cv::Size((int)m_VideoCapture->get(CV_CAP_PROP_FRAME_WIDTH), // Acquire input size + (int)m_VideoCapture->get(CV_CAP_PROP_FRAME_HEIGHT)); + std::string name = m_Controls.m_firstFile->text().toStdString(); + int ex = static_cast(m_VideoCapture->get(CV_CAP_PROP_FOURCC)); + //outputVideo1.open(name, ex = -1, m_VideoCapture->get(CV_CAP_PROP_FPS), S, true); + outputVideo1.open(name, cv::VideoWriter::fourcc('M','J','P','G'), 20, S, true); + } + if (m_Controls.m_SeparateWindow->isChecked()) { cv::namedWindow("Video", 1); while (m_running) { cv::Mat frame; *m_VideoCapture >> frame; // get a new frame from camera imshow("Video", frame); // Example to write a frame to a file: // imwrite("C:/temp/output.jpg", frame); // Press 'c' to stop the stream if (cv::waitKey(30) == 'c') break; + if (m_Controls.m_writeFile->isChecked()) + { + outputVideo1.write(frame); + } } } else if (m_Controls.m_MITKImage->isChecked()) { mitk::DataNode::Pointer imageNode = mitk::DataNode::New(); imageNode->SetName("Open CV Example Image Stream"); imageNode->SetData(mitk::Image::New()); m_conversionFilter = mitk::OpenCVToMitkImageFilter::New(); this->GetDataStorage()->Add(imageNode); OnUpdateImage(); // Initialize view on Image mitk::IRenderWindowPart *renderWindow = this->GetRenderWindowPart(); if (renderWindow != NULL) renderWindow->GetRenderingManager()->InitializeViews( imageNode->GetData()->GetGeometry(), mitk::RenderingManager::REQUEST_UPDATE_2DWINDOWS, true); // Start timer for update loop m_UpdateTimer->setInterval(20); m_UpdateTimer->start(); } } else { m_UpdateTimer->stop(); m_running = false; m_Controls.m_StartGrabbing->setText("Start Video Grabbing"); cv::destroyWindow("Video"); mitk::DataNode::Pointer imageNode = this->GetDataStorage()->GetNamedNode("Open CV Example Image Stream"); this->GetDataStorage()->Remove(imageNode); m_VideoCapture->release(); delete m_VideoCapture; } } void SimpleOpenCVExample::OnUpdateImage() { cv::Mat image; *m_VideoCapture >> image; IplImage ipl_img = image; m_conversionFilter->SetOpenCVImage(&ipl_img); m_conversionFilter->Update(); this->GetDataStorage()->GetNamedNode("Open CV Example Image Stream")->SetData(m_conversionFilter->GetOutput()); this->RequestRenderWindowUpdate(mitk::RenderingManager::REQUEST_UPDATE_ALL); } diff --git a/Examples/Plugins/org.mitk.example.gui.opencv/src/internal/SimpleOpenCVExampleControls.ui b/Examples/Plugins/org.mitk.example.gui.opencv/src/internal/SimpleOpenCVExampleControls.ui index 0638451444..0b04b67c2b 100644 --- a/Examples/Plugins/org.mitk.example.gui.opencv/src/internal/SimpleOpenCVExampleControls.ui +++ b/Examples/Plugins/org.mitk.example.gui.opencv/src/internal/SimpleOpenCVExampleControls.ui @@ -1,139 +1,260 @@ SimpleOpenCVExampleControls 0 0 262 - 418 + 455 0 0 QmitkTemplate Input ID Qt::Horizontal 40 20 Manual Resolution: Qt::Horizontal 40 20 10000 1280 10000 1024 Render in Separate Window true Render as MITK Image Start Video Grabbing + + + + Qt::Horizontal + + + + + + + Second Stream + + + + + + + + + Second Input ID + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 1 + + + + + + + + + Qt::Horizontal + + + + + + + Write Video File + + + + + + + + + First File: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + C:/temp/video1.avi + + + + + + + + + + + Second File: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + C:/temp/video2.avi + + + + + Qt::Vertical QSizePolicy::Expanding 20 220