Open CV: live webcam

Share your advanced PureBasic knowledge/code with the community.
AAT
Enthusiast
Enthusiast
Posts: 259
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Open CV: live webcam

Post by AAT »

This example works in Windows, try it in Linux.
In Windows you will need in openCV1.0 libraries:
highgui100.dll
cxcore100.dll
libguide40.dll

Code: Select all

; Live webcam with OpenCV
; AAT, 2011
;------------------------

#CV_WINDOW_AUTOSIZE = 1

 Structure IplImage
   nSize.i
   id.i
   nChannels.i
   alphaChannel.i
   depth.i 
   colorModel.b[4]
   channelSeq.b[4]
   dataOrder.i
   origin.i
   align.i
   width.i
   height.i
   *roi.l
   *maskROI.l
   *imageId.l
   *tileInfo.l
   imageSize.i
   *imageData.l
   widthStep.i
   BorderMode.i[4]
   BorderConst.i[4]
   *imageDataOrigin.l 
 EndStructure

;-- highgui --
  Prototype.l ProtocvNamedWindow(name.s, flags.l = #CV_WINDOW_AUTOSIZE)
  Prototype.l ProtocvDestroyWindow(name.s)
  Prototype.l ProtocvShowImage(name.s, image.l)
  Prototype.l ProtocvWaitKey(delay.l = 0)
  ;-- video in highgui --
  Prototype.l ProtocvCreateCameraCapture(Index.i)
  Prototype.l ProtocvGrabFrame(CapturePtr.l );
  Prototype.l ProtocvQueryFrame(CapturePtr.l);  
  Prototype.l ProtocvReleaseCapture(*CvCapture.l)  
;------------

If OpenLibrary(1, "highgui100.dll")
  pcvNamedWindow.ProtocvNamedWindow = GetFunction(1, "cvNamedWindow")
  pcvDestroyWindow.ProtocvDestroyWindow = GetFunction(1, "cvDestroyWindow")
  PcvShowImage.ProtocvShowImage = GetFunction(1, "cvShowImage")
  PcvWaitKey.ProtocvWaitKey = GetFunction(1, "cvWaitKey")  
  cvCreateCameraCapture.ProtocvCreateCameraCapture = GetFunction(1,"cvCreateCameraCapture")
  cvQueryFrame.ProtocvQueryFrame = GetFunction(1,"cvQueryFrame")
  cvReleaseCapture.ProtocvReleaseCapture = GetFunction(1,"cvReleaseCapture")
EndIf

win.i = pcvNamedWindow("Live Camera", #CV_WINDOW_AUTOSIZE)
*capture.l = cvCreateCameraCapture(0);
While(1) 
  *Image.IplImage = cvQueryFrame(*capture);
  If *Image
    ret.i = pcvShowImage("Live Camera", *Image) 
    If ret = 0                                    ; Window is closed
      Break
    EndIf  
    If pcvWaitKey(33) = 27                        ; Until Esc key pressed
      Break
    EndIf       
  Else
    Break
  EndIf                  
Wend   
cvReleaseCapture(@*capture)
pcvDestroyWindow("Live Camera")
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Open CV: live webcam

Post by IdeasVacuum »

....the range of downloads available is a bit confusing: http://sourceforge.net/projects/opencvl ... pencv-win/

Do you have a link for the DLLs?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Open CV: live webcam

Post by DarkDragon »

IdeasVacuum wrote:....the range of downloads available is a bit confusing: http://sourceforge.net/projects/opencvl ... pencv-win/

Do you have a link for the DLLs?
highgui100 => OpenCV 1.00
bye,
Daniel
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: Open CV: live webcam

Post by jesperbrannmark »

Any chance for a Mac version?
AAT
Enthusiast
Enthusiast
Posts: 259
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: Open CV: live webcam

Post by AAT »

IdeasVacuum wrote:...Do you have a link for the DLLs?
http://sourceforge.net/projects/opencvl ... v-win/1.0/
Download OpenCV_1.0.exe
vwidmer
Enthusiast
Enthusiast
Posts: 286
Joined: Mon Jan 20, 2014 6:32 pm

Re: Open CV: live webcam

Post by vwidmer »

Anyone get this working in Linux?

I tried:

Code: Select all

; Live webcam with OpenCV
; AAT, 2011
;------------------------

#CV_WINDOW_AUTOSIZE = 1

 Structure IplImage
   nSize.i
   id.i
   nChannels.i
   alphaChannel.i
   depth.i
   colorModel.b[4]
   channelSeq.b[4]
   dataOrder.i
   origin.i
   align.i
   width.i
   height.i
   *roi.long
   *maskROI.long
   *imageId.long
   *tileInfo.long
   imageSize.i
   *imageData.long
   widthStep.i
   BorderMode.i[4]
   BorderConst.i[4]
   *imageDataOrigin.long
 EndStructure

;-- highgui --
  Prototype.l ProtocvNamedWindow(name.s, flags.l = #CV_WINDOW_AUTOSIZE)
  Prototype.l ProtocvDestroyWindow(name.s)
  Prototype.l ProtocvShowImage(name.s, image.l)
  Prototype.l ProtocvWaitKey(delay.l = 0)
  ;-- video in highgui --
  Prototype.l ProtocvCreateCameraCapture(Index.i)
  Prototype.l ProtocvGrabFrame(CapturePtr.l );
  Prototype.l ProtocvQueryFrame(CapturePtr.l); 
  Prototype.l ProtocvReleaseCapture(*CvCapture.long) 
;------------

If OpenLibrary(1, "/usr/lib/libopencv_highgui.so")
  pcvNamedWindow.ProtocvNamedWindow = GetFunction(1, "cvNamedWindow")
  pcvDestroyWindow.ProtocvDestroyWindow = GetFunction(1, "cvDestroyWindow")
  PcvShowImage.ProtocvShowImage = GetFunction(1, "cvShowImage")
  PcvWaitKey.ProtocvWaitKey = GetFunction(1, "cvWaitKey") 
  cvCreateCameraCapture.ProtocvCreateCameraCapture = GetFunction(1,"cvCreateCameraCapture")
  cvQueryFrame.ProtocvQueryFrame = GetFunction(1,"cvQueryFrame")
  cvReleaseCapture.ProtocvReleaseCapture = GetFunction(1,"cvReleaseCapture")
EndIf

win.i = pcvNamedWindow("Live Camera", #CV_WINDOW_AUTOSIZE)
*capture.long = cvCreateCameraCapture(0);
While(1)
  *Image.IplImage = cvQueryFrame(*capture);
  If *Image
    RET.i = pcvShowImage("Live Camera", *Image)
    If RET = 0                                    ; Window is closed
      Break
    EndIf 
    If pcvWaitKey(33) = 27                        ; Until Esc key pressed
      Break
    EndIf       
  Else
    Break
  EndIf                 
Wend   
cvReleaseCapture(@*capture)
pcvDestroyWindow("Live Camera")
but get invalid memory access on

Code: Select all

*capture.long = cvCreateCameraCapture(0);
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
AAT
Enthusiast
Enthusiast
Posts: 259
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: Open CV: live webcam

Post by AAT »

Hi, vwidmer.
You should read the topic PureBasic Interface to OpenCV
You will find all the necessary libraries and examples.
Post Reply