Prev: wxWidget
Next: wxWidgets 2.6.3
From: Larry on 1 May 2006 19:55 Hi, My project does pretty much all that. See http://larryo.org/work/robotics/chorg.html - sorry there not much info there yet and pictures are a bit outdated (more then a year old). And, yes, I did manage to compile it on linux (redhat) to ... more then a year ago. True is I had some problems but not with the opencv integration but the webcam drives weren't really there like they should. I used wxwidgets 2.4 at the time ... I recon now with 2.6 there must be a more elegant way to handle the conversion . For camera integration in linux you can see the link I provide bellow my approach at the time(not 100% that was the one that worked or I re-write it meanwhile). Look in Ccamera.cpp in between defines for win32_larry and else(linux). However I think with the new opencv version a more elegant approach can be done. It much depends on your needs as well ... I need full control at frame level synchronized with the rest of the threads. Sorry for the mess in the code, I don't have other another cleaner example at the moment - and I have plenty of other "more" grey areas in my projects to worrie about at the moment :) Perhaps it wont be a bad idea to create sample on how to use these together whenever I get some time. Generally, I am happy with opencv. True, the development it's a bit slow but is not dead yet :). Let me know if I can be any further help Larry Links: http://larryo.org/web/work/robotics/chorg/camera.cpp http://larryo.org/web/work/robotics/chorg/camera.h http://larryo.org/web/work/robotics/chorg/mainframe.cpp http://larryo.org/web/work/robotics/chorg/mainframe.h http://larryo.org/web/work/robotics/chorg/camview.cpp http://larryo.org/web/work/robotics/chorg/camview.h A code extras: ******************************frame**************** In the frame you construct your cam viewer: // build cam canvas m_pCamView = new CCamView( panel1, wxPoint(5,15), wxSize(354, 256) ); *******************************window****************** then in CcamView (which extends wxWindow ) I do(first two methods are just used to handle the drawing in window by wxwidgets, the third method does the actual conversion from iplimage to bitmap) : //////////////////////////////////////////////////////////////////// // Method: OnPaint // Class: CCamView // Purose: on paint event // Input: reference to paint event // Output: nothing //////////////////////////////////////////////////////////////////// void CCamView::OnPaint( wxPaintEvent& event ) { wxPaintDC dc(this); Draw( dc ); } //////////////////////////////////////////////////////////////////// // Method: Draw // Class: CCamView // Purose: camera drawing // Input: reference to dc // Output: nothing //////////////////////////////////////////////////////////////////// void CCamView::Draw( wxDC& dc ) { // check if dc available if( !dc.Ok( ) ){ return; } m_bDrawing = true; dc.BeginDrawing(); int x,y,w,h; dc.GetClippingBox( &x, &y, &w, &h ); // if there is a new image to draw if( m_bNewImage ) { dc.DrawBitmap( m_pBitmap, x, y ); m_bNewImage = false; } else { // draw inter frame ? } dc.EndDrawing(); m_bDrawing = false; return; } // I call this method from the camera object to do the conversion to bitmap so I can display with wxwidgets - it might be a better way //////////////////////////////////////////////////////////////////// // Method: DrawCam // Class: CCamView // Purose: convert ipl image and handle other drawings // Input: ipl image pointer // Output: nothing //////////////////////////////////////////////////////////////////// void CCamView::DrawCam( IplImage* pImg ) { if( pImg ) { unsigned char *rawData; CvSize roiSize; int step = 0; cvGetRawData( pDstImg, &rawData, &step, &roiSize ); wxImage pWxImg = wxImage( 640,480, rawData, TRUE ); m_pBitmap = wxBitmap( pWxImg.Scale(m_nWidth, m_nHeight) ); m_bNewImage = true; m_bDrawing = false; Refresh( FALSE ); cvReleaseImage( &pDstImg ); } } ************************** Camera call********************************* pFrame = cvQueryFrame( m_pCapture ); if( pFrame ) { // if no video image if( !m_pVideoImg ) { cvReleaseImage( &m_pVideoImg ); m_pVideoImg = cvCreateImage( cvSize( m_nWidth, m_nHeight ), 8, 3 ); } if( pFrame->origin == 1 ) { //cvFlip( pFrame, m_pVideoImg, 0 ); //cvCvtColor( m_pVideoImg, m_pVideoImg, CV_BGR2RGB ); cvConvertImage( pFrame, m_pVideoImg, CV_CVTIMG_FLIP | CV_CVTIMG_SWAP_RB ); } else { cvCopy( pFrame, m_pVideoImg, 0 ); } m_pCameraView->DrawCam( m_pVideoImg ); ************************* frame camera control panel hack*************** This is a hack I did to get the camera control panel in wxwidgets - only for windows //////////////////////////////////////////////////////////////////// // Method: On Video Source // Class: CMainFrame // Purose: when video source menu option selected // Input: reference to event // Output: nothing //////////////////////////////////////////////////////////////////// void CMainFrame::OnVideoSource( wxCommandEvent& event ) { CCamView *pView = GetCameraView(); // for widnows do this #ifdef _WINDOWS // hack to get the windows handler typedef struct CvCaptureCAM_VFW { void* vtable; CAPDRIVERCAPS caps; HWND capWnd; VIDEOHDR* hdr; DWORD fourcc; HIC hic; IplImage* rgb_frame; IplImage frame; } CvCaptureCAM_VFW; CvCapture* ptest = pView->m_pCamera->m_pCapture; CvCaptureCAM_VFW* p = (CvCaptureCAM_VFW*) ptest; capDlgVideoSource( p->capWnd ); #elif _LINUX // else ... TODO #endif return; } //////////////////////////////////////////////////////////////////// // Method: On Video Format // Class: CMainFrame // Purose: when video format menu option selected // Input: reference to event // Output: nothing //////////////////////////////////////////////////////////////////// void CMainFrame::OnVideoFormat( wxCommandEvent& event ) { CCamView *pView = GetCameraView(); // for widnows do this #ifdef _WINDOWS // hack to get the windows handler typedef struct CvCaptureCAM_VFW { void* vtable; CAPDRIVERCAPS caps; HWND capWnd; VIDEOHDR* hdr; DWORD fourcc; HIC hic; IplImage* rgb_frame; IplImage frame; } CvCaptureCAM_VFW; CvCapture* ptest = pView->m_pCamera->m_pCapture; CvCaptureCAM_VFW* p = (CvCaptureCAM_VFW*) ptest; capDlgVideoFormat( p->capWnd ); #elif _LINUX // else ... TODO #endif return; }
From: Larry on 1 May 2006 20:11 Aaa, by the way Kristian, do you know any other alternatives? Until a few months ago I constantly did research on the net for such packages but could not find any as compact as opencv. Only bits and pieces. I also had many headaches trying to integrate gocr (for character and bar code recognition) in this package. However I am not very happy with the results ... integration worked fine (after editing many thousands of lines of code I managed to encapsulate the c code in c++ and then get it working with opencv and wxwidgets) however it didn't gave good results on webcam resolution :( .. and it's also too slow. So here I am, still digging for a good implementation. Larry
From: Larry on 1 May 2006 20:18 Sorry, the links are: http://larryo.org/work/robotics/chorg/camera.cpp http://larryo.org/work/robotics/chorg/camera.h http://larryo.org/work/robotics/chorg/mainframe.cpp http://larryo.org/work/robotics/chorg/mainframe.h http://larryo.org/work/robotics/chorg/camview.cpp http://larryo.org/work/robotics/chorg/camview.h
From: =?ISO-8859-1?Q?Kristian_N=F8rgaard?= on 2 May 2006 02:08 Larry wrote: >Aaa, by the way Kristian, do you know any other alternatives? > I haven't looked much into this but in my googling I stumbled across: vigra: http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ / Kristian --------------------------------------------------------------------- To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org
From: "Franco Amato" on 3 May 2006 15:05
Thanx very much for tour program..so you think it's slow? It run under window? It's compiled with wx2.4.2? Too many questions? Sorry Thank again. Best Regards Frank 1 May 2006 17:18:34 -0700, Larry <i(a)larryo.org>: > > > Sorry, the links are: > > http://larryo.org/work/robotics/chorg/camera.cpp > http://larryo.org/work/robotics/chorg/camera.h > http://larryo.org/work/robotics/chorg/mainframe.cpp > http://larryo.org/work/robotics/chorg/mainframe.h > http://larryo.org/work/robotics/chorg/camview.cpp > http://larryo.org/work/robotics/chorg/camview.h > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org > For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org > > |