#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")
img := cv.imread("test.png") ;读取图片
cv.line(img, ComArrayMake([0, 0]), ComArrayMake([511,511]), ComArrayMake([255,0,0]), 2)
;画线
;img代表传入的图像,[0,0]代表起始点坐标,[511,511]代表结束点坐标,[255,0,0]代表颜色RGB值,2代表线或圆等的厚度。如果传 -1 就是像圆的闭合图形,它将填充形状。
cv.rectangle(img,ComArrayMake([384,0]),ComArrayMake([510,128]),ComArrayMake([0,255,0]),2)
;画矩形
cv.circle(img,ComArrayMake([447,63]), 63, ComArrayMake([0,0,255]), -1)
;画圆
cv.ellipse(img,ComArrayMake([256,256]),ComArrayMake([100,50]),0,0,180,255,-1)
;画椭圆
pts := ComObjCreate("OpenCV.VectorOfpoint")
pts.push_back(ComArrayMake([0, 45]))
pts.push_back(ComArrayMake([0, 135]))
pts.push_back(ComArrayMake([85, 175]))
pts.push_back(ComArrayMake([175, 135]))
pts.push_back(ComArrayMake([175, 45]))
pts.push_back(ComArrayMake([85, 0]))
cv.polylines(img, pts, ComObj(0xB, -1), ComArrayMake([0,255,255]), 2)
;画多边形
NumPut(Scale := 3, temp := 0, "double")
Scale := NumGet(temp, "double")
cv.putText(img, "Hello Opencv", ComArrayMake([50, 450]), 0, Scale, ComArrayMake([0, 0, 255]), 2)
;给图像加文字
cv.imshow("Image", img) ;显示图片
cv.waitKey() ;等待按键输入,参数形式为ASCII 数值(例如a键为97)默认接收任意键
cv.destroyAllWindows() ;销毁所有opencv窗口
ComArrayMake(inputArray) ;这个函数用来转换参数,比如函数原来需要(0,0),调用这个函数ComArrayMake([0,0])就可以转换过去
{
arr := ComObjArray(VT_VARIANT:=12, inputArray.Length())
Loop,% inputArray.Length()
{
arr[A_Index-1] := inputArray[A_Index]
}
return arr
}
上面用到的dll和图片蓝奏云链接
天黑版opencv_ahk.dll使用(改变了调用方式,优化速度…)
相关文件:https://wwz.lanzouw.com/iAkK803eaaud
cv2.ahk和log.ahk来自社区群友zzZ…
可以用文件中的天黑版的v2h版ahk运行。
示例:绘图功能
#Dllload lib
#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'))
img := cv.imread("image/test.png")
cv.line(img, [0, 0], [511, 511], [255, 0, 0], 2)
;画线
cv.rectangle(img, [384, 0], [510, 128], [0, 255, 0], 2)
;画矩形
cv.circle(img, [447, 63], 63, [0, 0, 255], -1)
;画圆
cv.ellipse(img, [256, 256], [100, 50], 0, 0, 180, [255], -1)
;画椭圆
cv.polylines(img, cv.Vector_Point([[0, 45], [0, 135], [85, 175], [175, 135], [175, 45], [85, 0]]), true, [0, 255, 255], 2)
;画多边形
cv.putText(img, "Hello Opencv", [50, 450], 0, 3.0, [0, 0, 255], 2)
;给图像加文字
cv.TextDraw("仿宋", 40, 100, 0, 0).putText(img, '中文', [10, 120], [255 ,255, 255])
;给图像加中文文字
;TextDraw()5个参数 字体 字号 粗细 斜体 下划线
cv.imshow("image", img)
cv.waitKey()
cv.destroyAllWindows()
有错误请联系我改正!
本系列所有贡献者(AutoHotKey中文社区群友)不分先后:天黑请闭眼,zzZ…,演好自己,僵尸,城西,Tebayaki。
?
嗯
#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.dllDllInstall”, “int”, 1, “wstr”, A_IsAdmin = 0 ? “user” : “”, “cdecl”)
cv := ComObjCreate(“OpenCV.cv”)
img := cv.imread(“test.png”) ;读取图片
cv.line(img, OpencvAHK_Point([0, 0]), OpencvAHK_Point([511,511]), OpencvAHK_ConstScalar([255,0,0]), 2)
;画线
;img代表传入的图像,[0,0]代表起始点坐标,[511,511]代表结束点坐标,[255,0,0]代表颜色RGB值,2代表线或圆等的厚度。如果传 -1 就是像圆的闭合图形,它将填充形状。
cv.rectangle(img,OpencvAHK_Point([384,0]),OpencvAHK_Point([510,128]),OpencvAHK_ConstScalar([0,255,0]),2)
;画矩形
cv.circle(img,OpencvAHK_Point([447,63]), 63, OpencvAHK_ConstScalar([0,0,255]), -1)
;画圆
cv.ellipse(img,OpencvAHK_Point([256,256]),OpencvAHK_Point([100,50]),0,0,180,255,-1)
;画椭圆
cv.polylines(img, pts:=OpencvAHK_ConstPointConst([[0, 45],[0, 135],[85, 175],[175, 135],[175, 45],[85, 0]]), ComObj(0xB, -1), OpencvAHK_ConstScalar([0,255,255]), 2)
;画多边形
NumPut(Scale := 3, temp := 0, “double”)
Scale := NumGet(temp, “double”)
cv.putText(img, “Hello Opencv”, OpencvAHK_Point([50, 450]), 0, Scale, OpencvAHK_ConstScalar([0, 0, 255]), 2)
;给图像加文字
cv.imshow(“Image”, img) ;显示图片
cv.waitKey() ;等待按键输入,参数形式为ASCII 数值(例如a键为97)默认接收任意键
cv.destroyAllWindows() ;销毁所有opencv窗口
return
#Include opencv_ahk_lib.ahk
数据类型的转换,我做了一个封装,兴许能写的时候不那么痛苦!
https://www.autoahk.com/archives/39990
看到了,后续尝试一下
多谢老朱