<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Видео с веб камеры]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=7945&amp;type=atom" />
	<updated>2013-01-05T12:30:53Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=7945</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Видео с веб камеры]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=68175#p68175" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>artchi пишет:</cite><blockquote><p>Есть задача делать фото с usb веб камеры.<br />Найденный мной код c форума <a href="http://www.autohotkey.com/board/topic/16274-code-to-capture-from-webcam/">http://www.autohotkey.com/board/topic/1 … om-webcam/</a></p></blockquote></div><p>В этой же теме есть ссылка <a href="http://www.autohotkey.com/board/topic/15662-add-vfw-video-for-windows-to-ahk-gui-works-somewhat/#entry108361">Add VFW - Video for Windows to AHK GUI! [WORKS (somewhat)]</a>. У меня в окне программы отобржается сигнал с TV-tuner&#039;а (вернее помехи).</p>]]></content>
			<author>
				<name><![CDATA[ypppu]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=5974</uri>
			</author>
			<updated>2013-01-05T12:30:53Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=68175#p68175</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Видео с веб камеры]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=68174#p68174" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>Дело в том, что мне нужно добавить функцию к существующему коду на AHK</p></blockquote></div><div class="codebox"><pre><code>CreateWebCamSnapshot(filePath) {
    static ExtCode := {bmp: 0, jpg: 1, gif: 2, tif: 5, png: 6}
    static defaultExt := &quot;png&quot;
    static takePicture := &quot;{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}&quot;

    DeviceManager := ComObjCreate(&quot;WIA.DeviceManager&quot;)

    if !count := DeviceManager.DeviceInfos.Count
        return false

    SplitPath, filePath,,, ext
    if !ObjHasKey(ExtCode, ext)
        ext := defaultExt, filePath .= &quot;.&quot; . defaultExt

    imageCodec := &quot;{557CF40&quot; . ExtCode[ext] . &quot;-1A04-11D3-9A73-0000F81EF32E}&quot;

    loop %count%
        try (oDevice := DeviceManager.DeviceInfos(A_Index))
            &amp;&amp; (oDevice.Type = 3)
            &amp;&amp; oDevice
                .Connect()
                .ExecuteCommand(takePicture)
                .Transfer(imageCodec)
                .SaveFile(filePath)
}
CreateWebCamSnapshot(A_Desktop . &quot;\aaa.jpg&quot;)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[creature.ws]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26105</uri>
			</author>
			<updated>2013-01-05T11:56:51Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=68174#p68174</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Видео с веб камеры]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=68157#p68157" />
			<content type="html"><![CDATA[<p>Дело в том, что мне нужно добавить функцию к существующему коду на AHK. А фото в крайнем случае я сниму с превью экрана камеры, все равно оно нужно, чтобы было видно что снимаешь.</p>]]></content>
			<author>
				<name><![CDATA[artchi]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=29367</uri>
			</author>
			<updated>2013-01-05T00:11:35Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=68157#p68157</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Видео с веб камеры]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=68156#p68156" />
			<content type="html"><![CDATA[<p>Ну одно дело видео, и совсем другое фото.<br />Не через WinAPI, но через COM (WIA) оно проще: <a href="http://forum.script-coding.com/viewtopic.php?id=4327">WSH: получение снимка с веб-камеры</a></p><p>Кстати. А можно-ли через <strong>WIA</strong> взять <strong>видео</strong> (и уложить его в файл)? Кто-то пробовал?</p>]]></content>
			<author>
				<name><![CDATA[Aскет]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=29355</uri>
			</author>
			<updated>2013-01-05T00:08:16Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=68156#p68156</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Видео с веб камеры]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=68155#p68155" />
			<content type="html"><![CDATA[<p>Я попробовал еще несколько готовых программ для работы с usb камерами, с моей все они не смогли соединиться . Отпишитест, пожалуйста, у кого заработал прведенный выше AHK код, и укажите какая у вас камера.</p>]]></content>
			<author>
				<name><![CDATA[artchi]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=29367</uri>
			</author>
			<updated>2013-01-05T00:05:36Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=68155#p68155</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Видео с веб камеры]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=68154#p68154" />
			<content type="html"><![CDATA[<p>Здравствуйте. Есть задача делать фото с usb веб камеры.<br />Найденный мной код c форума <a href="http://www.autohotkey.com/board/topic/16274-code-to-capture-from-webcam/">http://www.autohotkey.com/board/topic/1 … om-webcam/</a>:<br /></p><div class="codebox"><pre><code>
#NoTrayIcon
#SingleInstance FORCE
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#Persistent
CoordMode Pixel, Screen  ; Interprets the coordinates below as relative to the screen rather than the active window.


;defaults
WDT := 320 ;width
HGT := 240 ;height
FPS := 15 ;frame per second
fileJPG = vidcap.jpg ;capture file name on the desktop - jpg
fileBMP = vidcap.bmp ;capture file name on the desktop - bmp
SENS := 80 ;motion detect sensitivity% (0%-100%)
MotionCheckTime := 500 ;msec - time period to check for motion

hModule := DllCall(&quot;LoadLibrary&quot;, &quot;str&quot;, &quot;avicap32.dll&quot;)

Gui, +lastfound
mgH := WinExist()
Gui, Add, GroupBox, x4 y4 w492 h100, Available Video Drivers
Gui, Add, ListView, x8 y20 w400 h80 gSelectDriver vCapDriversLV, Index|Name
Gui, Add, Picture, x434 y16 w32 h32 Icon204, %A_WinDir%\system32\shell32.dll
Gui, Add, Button, x412 y50 w80 h24 gRefreshDrivers, Refresh
Gui, Add, Button, x412 y76 w80 h24 gSelectDriver vSelectDriverB, Select

; --- Video preview section of Gui
Gui, Add, GroupBox, x4 y108 w492 h262, Video
Gui, Add, CheckBox, x10 y120 w100 h24 vPreviewToggleState gPreviewToggle, Preview video
Gui, Add, Text, x10 y160, width:
Gui, Add, Edit, x70 y160 w30 vWDT gdoWDT, %WDT%
Gui, Add, Text, x10 y190, height:
Gui, Add, Edit, x70 y190 w30 vHGT gdoGHT, %HGT%
Gui, Add, Text, x10 y220, fps:
Gui, Add, Edit, x70 y220 w30 vFPS gdoFPS, %FPS%
Gui, Add, Button, x110 y190 h24 gPreviewToggle, Change
Gui, Add, Button, x400 y160 h24 gCopyToClipBoard, Copy
Gui, Add, Text, x240 y193, Desktop\
Gui, Add, Edit, x290 y190 w100 vfileJPG gdoJPG, %fileJPG%
Gui, Add, Button, x400 y190 h24 gSenToFile2, Send to &amp;JPG
Gui, Add, Text, x240 y223, Desktop\
Gui, Add, Edit, x290 y220 w100 vfileBMP gdoBMP, %fileBMP%
Gui, Add, Button, x400 y220 h24 gSenToFile, Send to &amp;BMP
Gui, Add, Text, x10 y250, Sensitivity `%
Gui, Add, Edit, x90 y250 w30 vSENS gdoSENS, %SENS%
Gui, Add, Text, x10 y280, Motion check:
Gui, Add, Edit, x90 y280 w30 vMotionCheckTime gdoMOT, %MotionCheckTime%
Gui, Add, Text, x130 y280, msec
Gui, Add, Button, Disabled x130 y250 h24 gMotionToggle, Motion  ON

Gui, Font, cGray s14 bold, Arial
Gui, Add, Text, x10 y320 w300,

GoSub, RefreshDrivers

Gui, Show, x200 w500 h400, Video For Windows for AutoHotkey - VFW4AHK

Return



doMOT:
    ControlGetText,MotionCheckTime,Edit7,A
    If MotionToggleState
        SetTimer, CompareImages, % MotionCheckTime
Return

doSENS:
    ControlGetText,SENS,Edit6,A
Return

doWDT:
    ControlGetText,WDT,Edit1,A
Return

doGHT:
    ControlGetText,HGT,Edit2,A
Return

doJPG:
    ControlGetText,fileJPG,Edit4,A
Return

doBMP:
    ControlGetText,fileBMP,Edit5,A
Return

doFPS:
    ControlGetText,FPS,Edit3,A
Return

PreviewToggle:
  ControlGet,PreviewToggleState,Checked,,Button5,A
  If PreviewToggleState
  {
    Control,Enable,,Button10,A
    Gui, 2:Destroy
    Gui, 2:Add, Text, x0 y0 w%WDT% h%HGT% vVidPlaceholder
    GuiControl, +0x7, VidPlaceholder ; frame
    Gui 2:+LastFound
    hwndParent := WinExist()
    Gui, 2:Show, x750 w%WDT% h%HGT%, Viewer
    GoSub ConnectToDriver
  }
  Else
  {
    Control,Disable,,Button10,A
    Gui, 2:Destroy
    GoSub DisconnectDriver
  }
Return

MotionToggle:
  If MotionToggleState
  {
    MotionToggleState =
    ControlSetText,Button10,Motion ON,ahk_id %mgH%
    SetTimer, CompareImages, Off
    Sleep % 2*MotionCheckTime
    ControlSetText,Static10,,ahk_id %mgH%
  }
  Else
  {
    MotionToggleState = 1
    ControlSetText,Button10,Motion OFF,ahk_id %mgH%
    SetTimer, CompareImages, % MotionCheckTime
  }
Return


ConnectToDriver:
  ; --- Connect and preview - hwnd, x, y, w, h
  capHwnd := Cap_CreateCaptureWindow(hwndParent, 0, 0, WDT, HGT)

  WM_USER = 0x0400
  WM_CAP_START := WM_USER
  WM_CAP_GRAB_FRAME_NOSTOP := WM_USER + 61
  WM_CAP_FILE_SAVEDIB := WM_CAP_START + 25

  WM_CAP := 0x400
  WM_CAP_DRIVER_CONNECT := WM_CAP + 10
  WM_CAP_DRIVER_DISCONNECT := WM_CAP + 11
  WM_CAP_EDIT_COPY := WM_CAP + 30
  WM_CAP_SET_PREVIEW := WM_CAP + 50
  WM_CAP_SET_PREVIEWRATE := WM_CAP + 52
  WM_CAP_SET_SCALE := WM_CAP + 53
 
  ; Connect to driver
  if SelectedDriver =
  {
    if foundDriver
        SelectedDriver = 0
    else
    {
        MsgBox, 16, Error!, You didn&#039;t select a video driver`, and there seems to be no driver present.
        Return
    }
  }
  SendMessage, WM_CAP_DRIVER_CONNECT, %SelectedDriver%, 0, , ahk_id %capHwnd%
 
  ; Set the preview scale
  SendMessage, WM_CAP_SET_SCALE, 1, 0, , ahk_id %capHwnd%
 
  ; Set the preview rate in milliseconds
  MSC := round((1/FPS)*1000)
  SendMessage, WM_CAP_SET_PREVIEWRATE, MSC, 0, , ahk_id %capHwnd%
 
  ; Start previewing the image from the camera
  SendMessage, WM_CAP_SET_PREVIEW, 1, 0, , ahk_id %capHwnd%
 
Return


CompareImages:
    imagefile = %A_Desktop%\comp.BMP
    SendMessage, WM_CAP_FILE_SAVEDIB, 0, &amp;imagefile, , ahk_id %capHwnd%
    Sensitivity := (100-SENS)/100*255
    ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, *%Sensitivity% *w%WDT% *h%HGT% %imagefile%
    if ErrorLevel = 2
        ControlSetText,Static10,Search error,ahk_id %mgH%
    else if ErrorLevel = 1
        ControlSetText,Static10,MOTION!!!,ahk_id %mgH%
    else
        ControlSetText,Static10,STILL,ahk_id %mgH%
Return

CopyToClipBoard:
  SendMessage, WM_CAP_EDIT_COPY, 0, 0, , ahk_id %capHwnd%
Return


SenToFile2:
    SendMessage, WM_CAP_EDIT_COPY, 0, 0, , ahk_id %capHwnd%
    RunWait, C:\Program Files\IrfanView\i_view32.exe /clippaste /convert=%A_Desktop%\%fileJPG%   ;copies from clipboard to file
Return


SenToFile:
    imagefile = %A_Desktop%\%fileBMP%
    SendMessage, WM_CAP_FILE_SAVEDIB, 0, &amp;imagefile, , ahk_id %capHwnd%
return


DisconnectDriver:
  SendMessage, WM_CAP_DRIVER_DISCONNECT, 1, 0, , ahk_id %capHwnd%
Return


RefreshDrivers:
  foundDriver = 0
  LV_Delete()
  Loop
  {
    thisInfo := Cap_GetDriverDescription(A_Index-1)
    If thisInfo
    {
      foundDriver = 1
      LV_Add(&quot;&quot;, A_Index-1, thisInfo)
    }
    Else
      Break
  }
  If !foundDriver
  {
    LV_Delete()
    LV_Add(&quot;&quot;, &quot;&quot;, &quot;Could not get video drivers&quot;)
    GuiControl, Disable, CapDriversLV
    GuiControl, Disable, SelectDriverB
  }
Return
 
 
SelectDriver:
  FocusedRowNumber := LV_GetNext(0, &quot;F&quot;)  ; Find the focused row.
  if not FocusedRowNumber  ; No row is focused.
    return
  LV_GetText(SelectedDriver, FocusedRowNumber, 1)
Return


Cap_CreateCaptureWindow(hWndParent, x, y, w, h)
{
  WS_CHILD := 0x40000000
  WS_VISIBLE := 0x10000000
 
  lpszWindowName := &quot;test&quot;
 
  lwndC := DLLCall(&quot;avicap32.dll\capCreateCaptureWindowA&quot;
                  , &quot;Str&quot;, lpszWindowName
                  , &quot;UInt&quot;, WS_VISIBLE | WS_CHILD ; dwStyle
                  , &quot;Int&quot;, x
                  , &quot;Int&quot;, y
                  , &quot;Int&quot;, w
                  , &quot;Int&quot;, h
                  , &quot;UInt&quot;, hWndParent
                  , &quot;Int&quot;, 0)
 
  Return lwndC
}


Cap_GetDriverDescription(wDriver)
{
  VarSetCapacity(lpszName, 100)
  VarSetCapacity(lpszVer, 100)
  res := DLLCall(&quot;avicap32.dll\capGetDriverDescriptionA&quot;
                  , &quot;Short&quot;, wDriver
                  , &quot;Str&quot;, lpszName
                  , &quot;Int&quot;, 100
                  , &quot;Str&quot;, lpszVer
                  , &quot;Int&quot;, 100)
  If res
    capInfo := lpszName ; &quot; | &quot; lpszVer
  Return capInfo
}


GuiClose:
  GoSub, DisconnectDriver
  DllCall(&quot;FreeLibrary&quot;, &quot;str&quot;, hModule)
  ExitApp
Return
</code></pre></div><p>дает в превью черное окно.<br />В скайпе камера работает.</p>]]></content>
			<author>
				<name><![CDATA[artchi]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=29367</uri>
			</author>
			<updated>2013-01-04T23:32:54Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=68154#p68154</id>
		</entry>
</feed>
