I have a directory containg images which is updated at 4 second intervals these images are snapshots from 9 different cameras. 9 Images every 4 seconds with the exception being that when each camera's limit is reached that is 15 images per camera then those images are deleted - sorta like emptying a buffer. The file naming scheme is as follows (seconds since epoch & "." & last octet of the ip address & ".jpg") I need to get the most recent frame and display it in my GUI. It must be as fast as possible because there is already a 4 second delay. This an IP Camera Viewer. I've tried the code below but its not smooth and it freezes constantly.
It freezes after so many seconds and not all the images will display intially. If they don't display when I run the script then they are not updated. I'm stumbed on this. Any and all help appreciated thanks.
[ autoit ]
#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=..\..\Documents and Settings\root\Desktop\CamViewer.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> #include <Date.au3> HotKeySet("{ESC}", "_Exit") Global $hCamViewer, $hPic, $sCameraDir = "H:\Cam\Images" Global $aCamera[8][3] = [[171, "", 0], [172, "", 0], [173, "", 0], [174, "", 0], [175, "", 0], [176, "", 0], [177, "", 0], [178, "", 0]] Global Enum $iDev, $iCtrl , $iFrame Global Enum $iGS , $iPL FileChangeDir($sCameraDir) _SpawnViewer() Sleep(1000) AdlibRegister("_UpdateViewer", 4000) While 1 If GUIGetMsg() == $GUI_EVENT_CLOSE Then Exit EndIf Sleep(50) WEnd Func _UpdateDisplay($iCamera) Local $sImage = _SetImage($iCamera) If $sImage <> "" Then GUICtrlSetImage($aCamera[$iCamera][$iCtrl], $sImage, 0, 0) EndIf EndFunc Func _UpdateViewer() Local $bDelay = False If WinGetTitle($hCamViewer, "") == "Updating..." Then AdlibUnRegister("_UpdateViewer") $bDelay = True While WinGetTitle($hCamViewer, "") == "Updating..." Sleep(500) WEnd EndIf WinSetTitle($hCamViewer, "", "Updating...") For $iCamera = 0 To 7 Step 1 _UpdateDisplay($iCamera) Next WinSetTitle($hCamViewer, "", _Now()) If $bDelay == True Then AdlibRegister("_UpdateViewer", 3000) EndIf EndFunc Func _SpawnViewer() Local $sFrame = "" $hCamViewer = GUICreate("Updating...", @DesktopWidth, @DesktopHeight, -1, -1) Local $iLeft = 0, $iTop = 0, $iWidth = @DesktopWidth / 4, $iHeight = @DesktopHeight / 2 For $iCamera = 0 To 7 Step 1 $sFrame = _SetImage($iCamera) While Not FileExists($sFrame) $sFrame = _SetImage($iCamera) Sleep(500) WEnd $aCamera[$iCamera][$iCtrl] = GUICtrlCreatePic($sFrame, $iLeft, $iTop, $iWidth, $iHeight) $iLeft += $iWidth If $iLeft >= @DesktopWidth Then $iLeft = 0 $iTop += $iHeight EndIf Next GUISetState(@SW_SHOW) WinSetTitle($hCamViewer, "", _Now()) EndFunc Func _RequestImage($iCamera) Local $hImages = FileFindFirstFile("*." & $aCamera[$iCamera][$iDev] & ".jpg") Local $aJPG[30], $iCount = 0 While 1 $aJPG[$iCount] = FileFindNextFile($hImages) $iCount += 1 If @error Or $iCount == 49 Then ExitLoop WEnd Return _MostRecentFrame($aJPG) EndFunc Func _SetImage($iCamera) $aCamera[$iCamera][$iFrame] += 4 Local $sFrame = $aCamera[$iCamera][$iFrame] & "." & $aCamera[$iCamera][$iDev] & ".jpg" If FileExists($sFrame) Then If FileExists(($aCamera[$iCamera][$iFrame] + 4) & "." & $aCamera[$iCamera][$iDev] & ".jpg") Then $aCamera[$iCamera][$iFrame] += 4 $sFrame = $aCamera[$iCamera][$iFrame] & "." & $aCamera[$iCamera][$iDev] & ".jpg" ConsoleWrite("Camera #" & $aCamera[$iCamera][$iDev] & " Computed Frame: " & $sFrame & @CRLF) Return $sFrame EndIf ConsoleWrite("Camera #" & $aCamera[$iCamera][$iDev] & " Computed Frame: " & $sFrame & @CRLF) Return $sFrame EndIf $sFrame = _RequestImage($iCamera) Local $aFrame = StringSplit($sFrame, ".", 2) $aCamera[$iCamera][$iFrame] = $aFrame[0] ConsoleWrite("Camera #" & $aCamera[$iCamera][$iDev] & " Recent Frame: " & $aCamera[$iCamera][$iFrame] & @CRLF) Return $sFrame EndFunc Func _MostRecentFrame($aJPG) Local $iMax = 0 For $i = 0 To UBound($aJPG, 1) -1 If $aJPG[$i] = "" Then Return $aJPG[$iMax] EndIf If Int($aJPG[$i]) >= Int($aJPG[$iMax]) Then $iMax = $i EndIf Next Return $aJPG[$iMax] EndFunc Func _Exit() Exit EndFunc
It freezes after so many seconds and not all the images will display intially. If they don't display when I run the script then they are not updated. I'm stumbed on this. Any and all help appreciated thanks.