首页 > 其他分享 >AHK调用opencv(五)保存视频

AHK调用opencv(五)保存视频

时间:2022-10-12 10:14:45浏览次数:86  
标签:调用 AHK frame cap dll opencv cv out

;调用opencv录制视频并且保存为文件
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
hOpencv := DllCall("LoadLibrary", "str", "opencv_world455.dll", "ptr")
hOpencvCom := DllCall("LoadLibrary", "str", "autoit_opencv_com455.dll", "ptr")
DllCall("autoit_opencv_com455.dll\DllInstall", "int", 1, "wstr", A_IsAdmin = 0 ? "user" : "", "cdecl")
cv  := ComObjCreate("OpenCV.cv")
cap := ComObjCreate("OpenCV.cv.VideoCapture")
;fourcc := ComObjCreate("OpenCV.cv.VideoWriter_fourcc")
out := ComObjCreate("OpenCV.cv.VideoWriter")
codec := out.fourcc(asc("M"), asc("J"), asc("P"), asc("G")) ;这里函数接收char类型数据,所以用Tebayaki建议的asc()函数
NumPut(fps := 30, temp := 0, "double")
fps := NumGet(temp, "double")
; msgbox, % type(fps)
; type(v) {
;     if IsObject(v)
; 	{
; 		if ObjGetCapacity(v)>ObjCount(v)
; 			return "associative array"
; 		else
; 			return "array"
; 	}
;     return v="" || [v].GetCapacity(1) ? "String" : InStr(v,".") ? "Float" : "Integer"
; }
out.open("output.avi", codec, fps, ComArrayMake([640,480]))
frame := ComObjCreate("OpenCV.cv.MAT")
cap.open(0)
ComArrayMake(inputArray)
{
	arr := ComObjArray(VT_VARIANT:=12, inputArray.Length())
	Loop,% inputArray.Length()
	{
		arr[A_Index-1] := inputArray[A_Index]
	}
	return arr
}
While cap.isOpened(){
    ret := cap.read(frame)
	if ret{
		frame := cv.flip(frame, 1) ;0为翻转180度,1不翻转
		out.write(frame)
		cv.imshow("frame", frame)
	}
}
cap.release()
out.release()
cv.destroyAllWindows()

上面用到的dll和图片蓝奏云链接

https://wwm.lanzouw.com/iHcJi0033fob  

天黑版opencv_ahk.dll使用(改变了调用方式,优化速度...)

相关文件:https://wwz.lanzouw.com/iAkK803eaaud

播放视频依赖opencv_videoio_ffmpeg455_64.dll,链接https://wwz.lanzouw.com/iBP3A03ed1vi密码:fcd2

cv2.ahk和log.ahk来自社区群友zzZ...

可以用文件中的天黑版的v2h版ahk运行。

示例:保存视频

#DllLoad opencv_ahk.dll
#include <cv2>
#include <log>
SetWorkingDir A_ScriptDir
;初始化opencv模块
cv := ObjFromPtr(DllCall('opencv_ahk.dll\opencv_init', 'ptr', DllCall(A_AhkPath '\ahkGetApi', 'ptr'), 'cdecl ptr'))
cap := cv.VideoCapture()
frame := cv.Mat()
out := cv.VideoWriter()
codec := out.fourcc(Ord('M'), Ord('J'), Ord('P'), Ord('G'))
out.open("output.avi", codec, 30.0, [640, 480])
cap.open(0)
result := cap.isOpened()
while result{
    ret := cap.read(frame)
    if ret{
        out.write(frame)
        cv.imshow("image", frame)
    }
}
cap.release()
out.release()
cv.destroyAllWindows()

有错误请联系我改正!

本系列所有贡献者(AutoHotKey中文社区群友)不分先后:天黑请闭眼,zzZ...,演好自己,僵尸,城西,Tebayaki。

标签:调用,AHK,frame,cap,dll,opencv,cv,out
From: https://www.cnblogs.com/ff888/p/16783515.html

相关文章

  • AHK调用opencv(六)绘图功能
    #NoEnvSendModeInputSetWorkingDir%A_ScriptDir%hOpencv:=DllCall("LoadLibrary","str","opencv_world455.dll","ptr")hOpencvCom:=DllCall("LoadLibrary",......
  • AHK调用opencv(七)鼠标作为画笔
    #NoEnvSendModeInputSetWorkingDir%A_ScriptDir%hOpencv:=DllCall("LoadLibrary","str","opencv_world455.dll","ptr")hOpencvCom:=DllCall("LoadLibrary",......
  • AHK调用opencv(八)作为调色板的跟踪栏
    #NoEnv#Includeopencv_ahk_lib.ahkSendModeInputSetWorkingDir%A_ScriptDir%hOpencv:=DllCall("LoadLibrary","str","opencv_world455.dll","ptr")hOpencvCo......
  • OpenCV-图像读写(java版)
    @​​TOC​​图像读写Imgcodecs类中提供了图像的读写方法。使用imread()函数读取磁盘中的图像;使用imwrite()函数将图像写入磁盘中以下图为例演示。​​(图片来源网络)​​......
  • OpenCV-视频读写(java版)
    @​​TOC​​​​​OpenCV2中提供了两个类来实现视频的读写。读视频的类是​​VideoCapture​​,写视频的类是​​VideoWriter读视频VideoCapture既可以从视频文件读取图......
  • AHK调用opencv(四)播放视频文件
    本节内容对open()的另一种使用参数做了研究,注意这里open()里的参数是文件名。因为视频文件不同于相机,视频文件有时长,所以死循环中需要一个判断,判断视频帧是否结束,如果结束......
  • WebAssembly01--c代码调用js
    编译选项emcctest.c--js-librarypkg.js-otest.jspkg.jsmergeInto(LibraryManager.library,{js_add:function(a,b){console.log("js_add");......
  • Java 手动显示调用validate的实体属性验证
    importorg.springframework.util.CollectionUtils;importjavax.validation.ConstraintViolation;importjavax.validation.Valid;importjavax.validation.Validati......
  • JS 调用 FetchXML
    varcurUserid=Xrm.Utility.getGlobalContext().userSettings.userId;varfetchXml="<fetchversion='1.0'output-format='xml-platform'mapping='logical'dis......
  • OpenCV-像素值读写(java版)
    @​​TOC​​​很多时候,我们需要读取某个像素值,或者设置某个像素值,甚至需要遍历整个像素值。​​​OpenCV中RGB图像的通道为BGR!!!​​1.读像素值1.get()函数OpenCV中使用get......