Page 1 of 1

Open CV: live webcam

Posted: Mon Nov 14, 2011 2:16 pm
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")

Re: Open CV: live webcam

Posted: Mon Nov 14, 2011 4:10 pm
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?

Re: Open CV: live webcam

Posted: Mon Nov 14, 2011 5:11 pm
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

Re: Open CV: live webcam

Posted: Mon Nov 14, 2011 5:28 pm
by jesperbrannmark
Any chance for a Mac version?

Re: Open CV: live webcam

Posted: Tue Nov 15, 2011 1:21 pm
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

Re: Open CV: live webcam

Posted: Mon Jul 31, 2017 2:30 am
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);

Re: Open CV: live webcam

Posted: Mon Jul 31, 2017 12:36 pm
by AAT
Hi, vwidmer.
You should read the topic PureBasic Interface to OpenCV
You will find all the necessary libraries and examples.