mylise Posted May 1, 2013 Share Posted May 1, 2013 (edited) This is my first post to this fantastic website. Special thanks to UEZ, you have help me very much with you scripts! My last programming experience dates 15 years ago with Qbasic. 6 month ago I've decided to write a program that interfaces with a webcam. I started with Webcam.au3 (avicap32.dll) and got that working but when I ported it over to windows 7, niet. If people tell you that avicap32.dll has a maximum resolution of 640x480, do not listen to them So I tried Webcamds.au3 but who knows why, I do not understand how object oriented programming works. So I was not able to modify it to meet my needs by dshow was the way to go, so with much searching there are a few opensource DLL that does the job, ie. Touchless sdk, Escapi21, and Opencv. I've selected to continue with Opencv because of the available webcam settings. So... Here is how I access the webcam in Opencv and how I display it in Autoit. For it to work you must have opencv's version2.45 dll's and msvcp100.dll in the script's directory. My problem is it has a small memory leak which freezes the computer after a few days in operation and I do not know if it is the autoit part or opencv part that causes the problem. Hope someone here can help me. expandcollapse popup#include <GDIplus.au3> #include <Memory.au3> #include <GUIConstantsEx.au3> Global $_opencvDll_1, $_opencvDll_2, $_opencvDll_3 ;Different constant used by opencv for webcam settings Global Const $CV_CAP_PROP_POS_MSEC =0 Global Const $CV_CAP_PROP_POS_FRAMES =1 Global Const $CV_CAP_PROP_POS_AVI_RATIO =2 Global Const $CV_CAP_PROP_FRAME_WIDTH =3 Global Const $CV_CAP_PROP_FRAME_HEIGHT =4 Global Const $CV_CAP_PROP_FPS =5 Global Const $CV_CAP_PROP_FOURCC =6 Global Const $CV_CAP_PROP_FRAME_COUNT =7 Global Const $CV_CAP_PROP_FORMAT =8 Global Const $CV_CAP_PROP_MODE =9 Global Const $CV_CAP_PROP_BRIGHTNESS =10 Global Const $CV_CAP_PROP_CONTRAST =11 Global Const $CV_CAP_PROP_SATURATION =12 Global Const $CV_CAP_PROP_HUE =13 Global Const $CV_CAP_PROP_GAIN =14 Global Const $CV_CAP_PROP_EXPOSURE =15 Global Const $CV_CAP_PROP_CONVERT_RGB =16 Global Const $CV_CAP_PROP_WHITE_BALANCE_BLUE_U =17 Global Const $CV_CAP_PROP_RECTIFICATION =18 Global Const $CV_CAP_PROP_MONOCROME =19 Global Const $CV_CAP_PROP_SHARPNESS =20 Global Const $CV_CAP_PROP_AUTO_EXPOSURE =21 Global Const $CV_CAP_PROP_GAMMA =22 Global Const $CV_CAP_PROP_TEMPERATURE =23 Global Const $CV_CAP_PROP_TRIGGER =24 Global Const $CV_CAP_PROP_TRIGGER_DELAY =25 Global Const $CV_CAP_PROP_WHITE_BALANCE_RED_V =26 Global Const $CV_CAP_PROP_ZOOM =27 Global Const $CV_CAP_PROP_FOCUS =28 Global Const $CV_CAP_PROP_GUID =29 Global Const $CV_CAP_PROP_ISO_SPEED =30 Global Const $CV_CAP_PROP_MAX_DC1394 =31 Global Const $CV_CAP_PROP_BACKLIGHT =32 Global Const $CV_CAP_PROP_PAN =33 Global Const $CV_CAP_PROP_TILT =34 Global Const $CV_CAP_PROP_ROLL =35 Global Const $CV_CAP_PROP_IRIS =36 Global Const $CV_CAP_PROP_SETTINGS =37 Dim $CV_CAP[39] = ['CV_CAP_PROP_POS_MSEC','CV_CAP_PROP_POS_FRAMES','CV_CAP_PROP_POS_AVI_RATIO', _ 'CV_CAP_PROP_FRAME_WIDTH','CV_CAP_PROP_FRAME_HEIGHT','CV_CAP_PROP_FPS', _ 'CV_CAP_PROP_FOURCC','CV_CAP_PROP_FRAME_COUNT','CV_CAP_PROP_FORMAT', _ 'CV_CAP_PROP_MODE','CV_CAP_PROP_BRIGHTNESS','CV_CAP_PROP_CONTRAST', _ 'CV_CAP_PROP_SATURATION','CV_CAP_PROP_HUE','CV_CAP_PROP_GAIN', _ 'CV_CAP_PROP_EXPOSURE','CV_CAP_PROP_CONVERT_RGB','CV_CAP_PROP_WHITE_BALANCE_BLUE_U', _ 'CV_CAP_PROP_RECTIFICATION','CV_CAP_PROP_MONOCROME','CV_CAP_PROP_SHARPNESS', _ 'CV_CAP_PROP_AUTO_EXPOSURE','CV_CAP_PROP_GAMMA','CV_CAP_PROP_TEMPERATURE', _ 'CV_CAP_PROP_TRIGGER','CV_CAP_PROP_TRIGGER_DELAY','CV_CAP_PROP_WHITE_BALANCE_RED_V', _ 'CV_CAP_PROP_ZOOM','CV_CAP_PROP_FOCUS','CV_CAP_PROP_GUID','CV_CAP_PROP_ISO_SPEED', _ 'CV_CAP_PROP_MAX_DC1394','CV_CAP_PROP_BACKLIGHT','CV_CAP_PROP_PAN','CV_CAP_PROP_TILT', _ 'CV_CAP_PROP_ROLL','CV_CAP_PROP_IRIS','CV_CAP_PROP_SETTINGS'] Global $tagIplImage = _ "int nSize;" & _ ; /* sizeof(IplImage) */ "int ID;" & _ ; /* version (=0)*/ "int nChannels;" & _ ; /* Most of OpenCV functions support 1,2,3 or 4 channels */ "int alphaChannel;" & _ ; /* Ignored by OpenCV */ "int depth;" & _ ; /* Pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S, IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported. */ "byte colorModel[4];" & _ ; /* Ignored by OpenCV */ "byte channelSeq[4];" & _ ; /* ditto */ "int dataOrder;" & _ ; /* 0 - interleaved color channels, 1 - separate color channels.cvCreateImage can only create interleaved images */ "int origin;" & _ ; /* 0 - top-left origin,1 - bottom-left origin (Windows bitmaps style). */ "int align;" & _ ; /* Alignment of image rows (4 or 8). OpenCV ignores it and uses widthStep instead. */ "int width;" & _ ; /* Image width in pixels. */ "int height;" & _ ; /* Image height in pixels. */ "ptr IplROI;" & _ ; /* Image ROI. If NULL, the whole image is selected. */ "ptr maskROI;" & _ ; /* Must be NULL. */ "ptr imageId;" & _ ; "ptr tileInfo;" & _ ; "int imageSize;" & _ ; /* Image data size in bytes (==image->height*image->widthStep in case of interleaved data)*/ "ptr imageData;" & _ ; /* Pointer to aligned image data. */ "int widthStep;" & _ ; /* Size of aligned image row in bytes. */ "int BorderMode[4];" & _ ; /* Ignored by OpenCV. */ "int BorderConst[4];" & _ ; /* Ditto. */ "ptr imageDataOrigin;" ; /* Pointer to very origin of image data (not necessarily aligned) - needed for correct deallocation */ Dim $nIplImage[23] = ["nSize=", "ID=", "nChannels=" , "alphaChannel=", "depth=","colorModel[4]=","channelSeq[4]=","dataOrder=" , _ "origin=", "align=", "width=", "height=", "IplROI=", "maskROI=","imageId=", "tileInfo=","imageSize=","imageData=","widthStep=","BorderMode[4]=", _ "BorderConst[4]=", "imageDataOrigin="] Local $tagIplROI = _ "int coi;" & _ ; /* 0 - no COI (all channels are selected), 1 - 0th channel is selected ...*/ "int xOffset;" & _ "int yOffset;" & _ "int width;" & _ "int height;" ;Different constant used by opencv for selecting webcam ie. dshow web cam index would be 700, 701, 702, etc... Global Const $CV_CAP_ANY =0; // autodetect Global Const $CV_CAP_MIL =100; // MIL proprietary drivers Global Const $CV_CAP_VFW =200; // platform native Global Const $CV_CAP_V4L =200; Global Const $CV_CAP_V4L2 =200; Global Const $CV_CAP_FIREWARE =300; // IEEE 1394 drivers Global Const $CV_CAP_FIREWIRE =300; Global Const $CV_CAP_IEEE1394 =300; Global Const $CV_CAP_DC1394 =300; Global Const $CV_CAP_CMU1394 =300; Global Const $CV_CAP_STEREO =400; // TYZX proprietary drivers Global Const $CV_CAP_TYZX =400; Global Const $CV_TYZX_LEFT =400; Global Const $CV_TYZX_RIGHT =401; Global Const $CV_TYZX_COLOR =402; Global Const $CV_TYZX_Z =403; Global Const $CV_CAP_QT =500; // QuickTime Global Const $CV_CAP_UNICAP =600; // Unicap drivers Global Const $CV_CAP_DSHOW =700; // DirectShow (via videoInput) Global Const $CV_CAP_MSMF =1400; // Microsoft Media Foundation (via videoInput) Global Const $CV_CAP_PVAPI =800; // PvAPI, Prosilica GigE SDK Global Const $CV_CAP_OPENNI =900; // OpenNI (for Kinect) Global Const $CV_CAP_OPENNI_ASUS =910; // OpenNI (for Asus Xtion) Global Const $CV_CAP_ANDROID =1000; // Android Global Const $CV_CAP_XIAPI =1100; // XIMEA Camera API Global Const $CV_CAP_AVFOUNDATION = 1200; // AVFoundation framework for iOS (OS X Lion will have the same API) Global Const $CV_CAP_GIGANETIX = 1300; // Smartek Giganetix GigEVisionSDK Local $device = $CV_CAP_ANY Local $pIplImage Local $hBMP Local $x = 640 Local $y = 480 ;------------------------------------------------ ; Main _OpenCV_Startup() Local $pCvCapture = _OpenCV_WebCam($device) _Opencv_SetWebCam($pCvCapture,$x,$y) Local $hwnd = GUICreate("Opencv WebCam", $x, $y) GUISetState(@SW_SHOW,$hwnd) _GDIPlus_Startup() While 1 Local $msg = GUIGetMsg() $pIplImage = _Opencv_GetWebCamFrame($pCvCapture) $hBMP = _Opencv_IPL2BMP($pIplImage) Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hwnd) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $x, $y) _GDIPlus_BitmapDispose($hImage) _WinAPI_DeleteObject($hBMP) If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd DllCall($_opencvDll_1, "none:cdecl", "cvReleaseImage", "ptr*", $pIplImage) If @error Then ConsoleWrite("error2") _Opencv_CloseWebCam($pCvCapture) Exit ;------------------------------------------------ ; _OpenCV_WebCam($index = 0) ; ; $index is a value indicating the type of webcam and which webcam to select ; Returns a pointer to CVCapture ; Func _OpenCV_WebCam($index = 0) Local $_aResult = DllCall($_opencvDll_2, "int:cdecl", "cvCreateCameraCapture", "int", $index) If @error Then MsgBox(0,"","Can not find webcam") Return $_aResult[0] EndFunc ;==>_OpenCV_WebCam ;------------------------------------------------ ; _Opencv_SetWebCam($pCvCapture, $x=640, $y=480 ) ; ; $pCvCapture is a a pointer to CVCapture linked to the webcam and obtained from _OpenCV_WebCam() function ; $x,$y are used to set the width and height of the webcam. If resolutionis not supported, it will select the next lowest one! ; Func _Opencv_SetWebCam($pCvCapture, $x=640, $y=480 ) ;Un-comment these lines of code if you want to see available setting for webcam ;For $i = 0 to 37 ; Local $_aResult = DllCall($_opencvDll_2, "double:cdecl", "cvGetCaptureProperty", "ptr", $pCvCapture, "int", $i) ; If @error Then ConsoleWrite("error1") ; ConsoleWrite($CV_CAP[$i] & "=" & $_aResult[0] & @CRLF) ;Next Local $_aResult = DllCall($_opencvDll_2, "int:cdecl", "cvSetCaptureProperty", "ptr", $pCvCapture, "int", $CV_CAP_PROP_FRAME_WIDTH, "double", $x) If @error Then ConsoleWrite("error2") Local $_aResult = DllCall($_opencvDll_2, "int:cdecl", "cvSetCaptureProperty", "ptr", $pCvCapture, "int", $CV_CAP_PROP_FRAME_HEIGHT, "double", $y) If @error Then ConsoleWrite("error3") EndFunc ;==>_Opencv_SetWebCam ;------------------------------------------------ ; _Opencv_GetWebCamFrame($pCvCapture) ; ; $pCvCapture is a a pointer to CVCapture linked to the webcam and obtained from _OpenCV_WebCam() function ; ; Returns a pointer to the captured frame in an IplImage format ; Func _Opencv_GetWebCamFrame($pCvCapture) $_aResult = DllCall($_opencvDll_2, "int:cdecl", "cvQueryFrame", "ptr", $pCvCapture) If @error Then ConsoleWrite("error4") Return $_aResult[0] EndFunc ;==>_Opencv_GetWebCamFrame ;------------------------------------------------ ; _Opencv_IPL2BMP($pIplImage) ; ; $pIplImage is a a pointer to IplImage of type 8UC3 (24bits) created by opencv ; ; Returns a pointer to GDI compatible bitmap image ; Author: Mylise ; Func _Opencv_IPL2BMP($pIplImage) Local $tIplImage = DllStructCreate($tagIplImage, $pIplImage) ;Un-comment these lines of code if you want to see IplImage header information ;for $i = 1 to 22 ; ConsoleWrite( $nIplImage[$i-1] & DllStructGetData($tIplImage,$i) & @CRLF) ;Next $_aResult = DllCall($_opencvDll_1, "int:cdecl", "cvCreateImage", "int", DllStructGetData($tIplImage,'width'), "int", DllStructGetData($tIplImage,'height'), "int", 8, "int", 4 ) If @error Then ConsoleWrite("error5") Local $pIplImagedst = $_aResult[0] Local $tIplImagedst = DllStructCreate($tagIplImage, $pIplImagedst) DllCall($_opencvDll_3, "none:cdecl", "cvCvtColor", "ptr", $pIplImage, "ptr", $pIplImagedst, "int", 0) If @error Then ConsoleWrite("error6" & @error & @CRLF) Local $dataptr= DllStructGetData($tIplImagedst,'imageData') Local $hBMP = _WinAPI_CreateBitmap(DllStructGetData($tIplImagedst,'width'), DllStructGetData($tIplImagedst,'height'), 1, 32 , $dataptr) ;memory cleanup $tIplImage = 0 $tIplImagedst = 0 $dataptr = 0 DllCall($_opencvDll_1, "none:cdecl", "cvReleaseImage", "ptr*", $pIplImagedst) If @error Then ConsoleWrite("error7") Return $hBMP EndFunc ;==>_Opencv_GetWebCamFrame ;------------------------------------------------ ; _Opencv_CloseWebCam($pCvCapture) ; ; $pCvCapture is a a pointer to CVCapture linked to the webcam and obtained from _OpenCV_WebCam() function ; Func _Opencv_CloseWebCam($pCvCapture) DllCall($_opencvDll_2, "none:cdecl", "cvReleaseCapture", "ptr*", $pCvCapture) If @error Then ConsoleWrite("error8") DllClose($_opencvDll_1) DllClose($_opencvDll_2) DllClose($_opencvDll_3) EndFunc ;==>_Opencv_CloseWebCam ;------------------------------------------------ ; _OpenCV_Startup() ; ; ; Func _OpenCV_Startup() $_opencvDll_1 = DllOpen("opencv_core245.dll") $_opencvDll_2 = DllOpen("opencv_highgui245.dll") $_opencvDll_3 = DllOpen("opencv_imgproc245.dll") EndFunc ;==>_OpenCV_Startup Thank you Edited May 2, 2013 by mylise Link to comment Share on other sites More sharing options...
UEZ Posted May 1, 2013 Share Posted May 1, 2013 (edited) I don't have a webcam but you forgot to dispose the graphics handle. While 1 Local $msg = GUIGetMsg() $pIplImage = _Opencv_GetWebCamFrame($pCvCapture) $hBMP = _Opencv_IPL2BMP($pIplImage) Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hwnd) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $x, $y) _GDIPlus_BitmapDispose($hImage) _GDIPlus_GraphicsDispose($hGraphics) _WinAPI_DeleteObject($hBMP) If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd Probably you have to release $pIplImage, too. Br, UEZ Edited May 1, 2013 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
mylise Posted May 2, 2013 Author Share Posted May 2, 2013 Thank you I modified my program with your recommendation and at first glance it seems to have corrected the memory leak. I do not know why but the $pIplImage pointer can not be released as long as the webcam is used. That is why it is outside the while loop. Link to comment Share on other sites More sharing options...
UEZ Posted May 2, 2013 Share Posted May 2, 2013 Btw, this is not a practise to create a gfx handle, put an image into it and finally dispose it afterwards. Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
mylise Posted May 2, 2013 Author Share Posted May 2, 2013 Yep, I saw that and took out the graphics handler and disposal outside of while loop. Thanks. Since you do not have a webcam, here is a function to load an image and 2 other functions that I use for image processing. The main is an example on how to use them. Do not forget to add other functions from the first post for this to work. Have fun! expandcollapse popup;------------------------------------------------ ; Main Local $filename = "" _OpenCV_Startup() Global $hwnd = GUICreate("Opencv WebCam", 960, 480) GUISetState(@SW_SHOW,$hwnd) _GDIPlus_Startup() Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hwnd) dim $xw[5] = [0,320,640,0,320] dim $yh[5] = [0,0,0,240,240] for $i = 0 to 4 $pIplImage = _OpenCV_FileImage($filename) _Opencv_cvZoom($pIplImage, 2, $i) _Opencv_cvSmooth($pIplImage , 4, 3) $hBMP = _Opencv_IPL2BMP($pIplImage) Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, $xw[$i], $yh[$i], 320, 240) _GDIPlus_BitmapDispose($hImage) _WinAPI_DeleteObject($hBMP) next While 1 Local $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop sleep(50) WEnd _GDIPlus_GraphicsDispose($hGraphics) DllCall($_opencvDll_1, "none:cdecl", "cvReleaseImage", "ptr*", $pIplImage) If @error Then ConsoleWrite("error2") DllClose($_opencvDll_1) DllClose($_opencvDll_2) DllClose($_opencvDll_3) Exit expandcollapse popup;------------------------------------------------ ; _OpenCV_FileImage($filename) ; ; $filename is a string identifying the location of image file if $filename = "" then autoi file open dialog box will appear ; ; Returns a pointer of loaded image in an IplImage format ; Func _OpenCV_FileImage(ByRef $filename ) If $filename = "" Then $filename = FileOpenDialog( "Select graphic file", @ScriptDir & "\", "Images (*.jpg;*.bmp;*.png)", 3,"",$hwnd ) ;ConsoleWrite("error2" & $filename ) $_aResult = DllCall($_opencvDll_2, "int:cdecl", "cvLoadImage", "str", $filename, "int", 1 ) If @error Then ConsoleWrite("error2") Return $_aResult[0] EndFunc ;==>_Opencv_FileImage ;------------------------------------------------ ; _Opencv_cvSmooth($pIplImage, $type = 2, $matrixsize = 3) ; ; $pIplImage is a pointer to IplImage of type 8UC3 (24bits) created by opencv ; $type = CV_BLUR_NO_SCALE =0, CV_BLUR =1, CV_GAUSSIAN =2, CV_MEDIAN =3, CV_BILATERAL =4 ; $matrixsize = size of pixel array that filter is using ; $param3 and $param4 = used for arpature size, recommended to use odd positive numbers ; Author = Mylise ; ; Func _Opencv_cvSmooth(ByRef $pIplImage, $type = 2, $matrixsize = 3, $param3 = 1, $param4 = 1) $_aResult = DllCall($_opencvDll_1, "int:cdecl", "cvCloneImage", "ptr", $pIplImage ) Local $pIplImagedst = $_aResult[0] DllCall($_opencvDll_3, "none:cdecl", "cvSmooth", "ptr", $pIplImage, "ptr", $pIplImagedst, "int", $type, "int", $matrixsize, "int", $matrixsize, "double" , $param3, "double" , $param4) If @error Then ConsoleWrite("error3" & @error & @CRLF) DllCall($_opencvDll_1, "none:cdecl", "cvCopy", "ptr", $pIplImagedst, "ptr", $pIplImage, "ptr", 0) If @error Then ConsoleWrite("error3" & @error & @CRLF) DllCall($_opencvDll_1, "none:cdecl", "cvReleaseImage", "ptr*", $pIplImagedst) If @error Then ConsoleWrite("error7") EndFunc ;==>_Opencv_cvSmooth ;------------------------------------------------ ; _Opencv_cvZoom($pIplImage, $factor = 1, $type = 1) ; ; $pIplImage is a pointer to IplImage of type 8UC3 (24bits) created by opencv ; $factor is zoom factor from center of image ; $type = CV_INTER_NN=0, CV_INTER_LINEAR=1, CV_INTER_CUBIC=2, CV_INTER_AREA=3, CV_INTER_LANCZOS4 =4 ; Author = Mylise ; Func _Opencv_cvZoom(ByRef $pIplImage, $factor = 1 , $type = 1) $_aResult = DllCall($_opencvDll_1, "int:cdecl", "cvCloneImage", "ptr", $pIplImage ) Local $pIplImagedst = $_aResult[0] Local $tIplImage = DllStructCreate($tagIplImage, $pIplImage) Local $Kzoom = ($factor-1)/(2*$factor) Local $x = int(DllStructGetData($tIplImage,'width') * $Kzoom) Local $y = int(DllStructGetData($tIplImage,'height') * $Kzoom) Local $width = int(DllStructGetData($tIplImage,'width') / $factor) Local $height = int(DllStructGetData($tIplImage,'height') / $factor) DllCall($_opencvDll_1, "none:cdecl", "cvSetImageROI", "ptr", $pIplImage, "int", $x, "int", $y, "int", $width, "int", $height) If @error Then ConsoleWrite("error1" & @error & @CRLF) DllCall($_opencvDll_3, "none:cdecl", "cvResize", "ptr", $pIplImage, "ptr", $pIplImagedst, "int", $type) If @error Then ConsoleWrite("error2" & @error & @CRLF) DllCall($_opencvDll_1, "none:cdecl", "cvResetImageROI", "ptr", $pIplImage) If @error Then ConsoleWrite("error3" & @error & @CRLF) DllCall($_opencvDll_1, "none:cdecl", "cvCopy", "ptr", $pIplImagedst, "ptr", $pIplImage, "ptr", 0) If @error Then ConsoleWrite("error4" & @error & @CRLF) DllCall($_opencvDll_1, "none:cdecl", "cvReleaseImage", "ptr*", $pIplImagedst) If @error Then ConsoleWrite("error5") EndFunc ;==>_Opencv_cvZoom Link to comment Share on other sites More sharing options...
GrandMaster Posted May 25, 2013 Share Posted May 25, 2013 how to take a screenshot using opencv? Link to comment Share on other sites More sharing options...
mylise Posted May 26, 2013 Author Share Posted May 26, 2013 (edited) how to take a screenshot using opencv? There is this but I have not used it! https://github.com/acdx/opencv-screen-capture What I have used instead, Autoit printscreen and clipboard functions, then saving in a file and opening it up with opencv. I was lazy and did not want to write a BMP2IPL function! Quick and dirty but slow. Send( "{PRINTSCREEN}") If Not _ClipBoard_Open(0) Then _WinAPI_ShowError("_ClipBoard_Open failed") local $hBMP = _ClipBoard_GetDataEx(2) local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\opencv.jpg") _ClipBoard_Close() _GDIPlus_BitmapDispose($hBitmap) $pIplImage = _OpenCV_FileImage(@ScriptDir & "\opencv.jpg") Do not forget to add the includes and _OpenCV_FileImage function for this to work. Edited May 26, 2013 by mylise Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now