Share your advanced PureBasic knowledge/code with the community.
			
		
		
			
				
																			
								AAT 							 
						Enthusiast 			
		Posts:  260  		Joined:  Sun Jun 15, 2008 3:13 am 		
		
						
						
		 
		
						
						
													
							
						
									
						Post 
					 
								by AAT   »  Mon Nov 14, 2011 2:16 pm 
			
			
			
			
			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")
 
			
			
									
									
						 
		 
				
		
		 
	 
				
			
	
						
		
		
			
				
																			
								DarkDragon 							 
						Addict 			
		Posts:  2347  		Joined:  Mon Jun 02, 2003 9:16 am 		
		
																										Location:  Germany 
							
							
				Contact: 
				
			 
				
		 
		
						
						
													
							
						
									
						Post 
					 
								by DarkDragon   »  Mon Nov 14, 2011 5:11 pm 
			
			
			
			
			
highgui100 => OpenCV 1.00
 
			
			
									
									bye, 
Daniel
						 
		 
				
		
		 
	 
	
						
	
						
	
						
		
		
			
				
																			
								vwidmer 							 
						Enthusiast 			
		Posts:  286  		Joined:  Mon Jan 20, 2014 6:32 pm 		
		
						
						
		 
		
						
						
													
							
						
									
						Post 
					 
								by vwidmer   »  Mon Jul 31, 2017 2:30 am 
			
			
			
			
			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 			
		Posts:  260  		Joined:  Sun Jun 15, 2008 3:13 am 		
		
						
						
		 
		
						
						
													
							
						
									
						Post 
					 
								by AAT   »  Mon Jul 31, 2017 12:36 pm 
			
			
			
			
			Hi, vwidmer.
You should read the topic 
PureBasic Interface to OpenCV 
You will find all the necessary libraries and examples.