OpenCV系列 - 作者:cc   原链接:https://www.cnblogs.com/ff888/p/16783853.html

#NoEnv
#Include opencv_ahk_lib.ahk
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")
global img := cv.imread("3.png")
margin   := 5
radius   := 220
center_x := 225
center_y := 225
cv.circle(img,OpencvAHK_Point([center_x,center_y]), radius, OpencvAHK_ConstScalar([0,0,0]), margin)
i := 1
Loop, 60{
    x1 := center_x + (radius - margin) * Cos(i*6*3.14/180)
    y1 := center_y + (radius - margin) * Sin(i*6*3.14/180)
    x2 := center_x + (radius - 15) * Cos(i*6*3.14/180)
    y2 := center_y + (radius - 15) * Sin(i*6*3.14/180)
    cv.line(img, OpencvAHK_Point([x1, y1]), OpencvAHK_Point([x2,y2]), OpencvAHK_ConstScalar([0,0,0]), 2)
    i += 1
}
i := 1
Loop, 12{
    x  := center_x + (radius - 5) * Cos(i*30*3.14/180)
    y  := center_y + (radius - 5) * Sin(i*30*3.14/180)
    x3 := center_x + (radius - 20) * Cos(i*30*3.14/180)
    y3 := center_x + (radius - 20) * Sin(i*30*3.14/180)
    cv.line(img, OpencvAHK_Point([x3, y3]), OpencvAHK_Point([x,y]), OpencvAHK_ConstScalar([0,0,0]), 5)
    i += 1
}
While, true{
    hour   := A_Hour
    minute := A_Min
    second := A_Sec
    temp   := img.copy()
    if (second <= 15)
        sec_angle := second*6+270
    Else
        sec_angle := (second-15)*6
    sec_x  := center_x + (radius - margin) * Cos(sec_angle*3.14/180)
    sec_y  := center_y + (radius - margin) * Sin(sec_angle*3.14/180)
    cv.line(temp, OpencvAHK_Point([225, 225]), OpencvAHK_Point([sec_x,sec_y]), OpencvAHK_ConstScalar([255,0,0]), 2)
    if (minute <= 15)
        min_angle := minute*6+270
    Else
        min_angle := (minute-15)*6
    min_x  := center_x + (radius - 35) * Cos(min_angle*3.14/180)
    min_y  := center_y + (radius - 35) * Sin(min_angle*3.14/180)
    cv.line(temp, OpencvAHK_Point([225, 225]), OpencvAHK_Point([min_x,min_y]), OpencvAHK_ConstScalar([0,255,0]), 8)
    if (hour <= 3)
        hour_angle := hour*30+270
    Else
        hour_angle := (hour-3)*30
    hour_x  := center_x + (radius - 75) * Cos(hour_angle*3.14/180)
    hour_y  := center_y + (radius - 75) * Sin(hour_angle*3.14/180)
    cv.line(temp, OpencvAHK_Point([225, 225]), OpencvAHK_Point([hour_x,hour_y]), OpencvAHK_ConstScalar([0,0,255]), 20)
    NumPut(Scale := 1, temp1 := 0, "double")
    time_str = %A_YYYY%/%A_MM%/%A_DD%
    cv.putText(temp, time_str, ComArrayMake([135, 275]), 0, Scale, ComArrayMake([0, 0, 0]), 2)
    cv.imshow("OpenCV clock", temp)
}
cv.waitKey()
cv.destroyAllWindows()

opencv_ahk_lib.ahk  by河许人

;char类型
OpencvAHK_char(char)
{
   Return asc(char)
}
;double类型
OpencvAHK_double(Number)
{
    NumPut(fps := Number, temp := 0, "double")
    Return fps := NumGet(temp, "double")
}
;布尔类型
OpencvAHK_bool(inputbool)
{
    ComObj(0XB,inputbool==ture?-1:0)
}
;const Point *const *
OpencvAHK_ConstPointConst(inputArray)
{
    pts := ComObjCreate("OpenCV.VectorOfpoint") 
    Loop,% inputArray.Length()
    {
        pts.push_back(ComArrayMake(inputArray[a_index]))
    }
    return pts
}
;Point类型
OpencvAHK_Point(inputArray)
{
    return ComArrayMake(inputArray) 
}
;Size类型(与piont类型都是一样的,只是为了写出的代码方便理解)
OpencvAHK_Size(inputArray)
{
    return ComArrayMake(inputArray) 
}
;构造返回数组
OpencvAHK_OutputArray()
{
    return frame := ComObjCreate("OpenCV.cv.MAT")
}
;颜色类型 Const Scalar &
OpencvAHK_ConstScalar(inputArray)
{
    return ComArrayMake(inputArray) 
}
ComArrayMake(inputArray) 
{
  arr := ComObjArray(VT_VARIANT:=12, inputArray.Length())
  Loop,% inputArray.Length()
  {
    arr[A_Index-1] := inputArray[A_Index]
  }
  return arr
}

上面用到的dll链接

https://wwm.lanzouw.com/ixoj200gbcaf

 

dbgba优化整理OpenCV系列示例打包下载20240513:

 

python版原文链接

https://blog.csdn.net/Ibelievesunshine/article/details/105291637

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。