source: eviacam/trunk/fuentes/wxcamwindow/capturethread.cpp @ 29

Last change on this file since 29 was 29, checked in by mabarracus, 4 years ago

added eviacam content

  • Property svn:executable set to *
File size: 2.6 KB
Line 
1/////////////////////////////////////////////////////////////////////////////
2// Name:        capturethread.cpp
3// Purpose:             
4// Author:      Cesar Mauri Loba (cesar at crea-si dot com)
5// Modified by:
6// Created:     
7// Copyright:   (C) 2008 Cesar Mauri Loba - CREA Software Systems
8//
9//  This program is free software: you can redistribute it and/or modify
10//  it under the terms of the GNU General Public License as published by
11//  the Free Software Foundation, either version 3 of the License, or
12//  (at your option) any later version.
13//
14//  This program is distributed in the hope that it will be useful,
15//  but WITHOUT ANY WARRANTY; without even the implied warranty of
16//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17//  GNU General Public License for more details.
18//
19//  You should have received a copy of the GNU General Public License
20//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21/////////////////////////////////////////////////////////////////////////////
22
23#ifdef __GNUG__
24#pragma implementation
25#pragma interface
26#endif
27
28#ifndef  WX_PRECOMP
29  #include "wx/wx.h"
30#endif //precompiled headers
31
32#include <cv.h>
33
34#include "capturethread.h"
35#include "crvcamera.h"
36#include "camwindow.h"
37
38// Constructor
39CCaptureThread::CCaptureThread (CCamera *pCamera, CCamWindow *pCamWindow, 
40                                                CProcessImage *pProcessImage, wxThreadKind kind) : wxThread (kind)
41{
42        assert (pCamera!= NULL);
43        m_pCamera= pCamera;
44        m_pCamWindow= pCamWindow;
45        m_pProcessImage= pProcessImage;
46        m_Life = true;
47}
48
49// Destructor
50CCaptureThread::~CCaptureThread ()
51{
52}
53
54wxThreadError CCaptureThread::Create(unsigned int stackSize)
55{
56        if (m_pCamera== NULL) return wxTHREAD_NO_RESOURCE;
57        //if (!m_pCamera->Open()) return wxTHREAD_NO_RESOURCE;
58
59        return wxThread::Create (stackSize);
60}
61
62wxThread::ExitCode CCaptureThread::Entry( )
63{
64        // Camera shold be opened inside calling thread
65        if (!m_pCamera->Open())
66        {
67                // This code never should be reached, but it may happen: there is a race condition between
68                // testing camera availabiliy and effectively using it.
69                wxMessageDialog errorMsg (NULL, _("Camera not detected. Aborting"), _("eViacam error"), wxOK | wxICON_ERROR);
70                errorMsg.ShowModal();
71                exit (0);
72        }
73
74        // Start thread main loop
75        while (m_Life)
76        {
77                if (TestDestroy()) break;
78               
79                IplImage* pImg= m_pCamera->QueryFrame();
80
81                if (pImg== NULL) wxMilliSleep(20); // If no result wait some time to avoid consuming all CPU
82                else {
83                        if (m_pProcessImage) m_pProcessImage->ProcessImage (pImg);
84                        if (m_pCamWindow) m_pCamWindow->DrawCam (pImg); 
85                }
86        }
87
88        m_pCamera->Close();
89       
90        return NULL;
91}
Note: See TracBrowser for help on using the repository browser.