OpenCV系列 - 作者:cc   原链接:https://www.cnblogs.com/ff888/p/16783532.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("2.png") ;读取图片
global rows := img.rows()
global cols := img.cols()
cv.namedWindow("Image")
global r := 0
global g := 0
global b := 0
VarSetCapacity(r, 8)
VarSetCapacity(g, 8)
VarSetCapacity(b, 8)
callback_R := RegisterCallback("TheFunc_R", "CDecl")
callback_G := RegisterCallback("TheFunc_G", "CDecl")
callback_B := RegisterCallback("TheFunc_B", "CDecl")
DllCall("opencv_world455.dll\cvCreateTrackbar", "Astr", "R", "Astr", "Image", "ptr", &r, "int", 255,"ptr", callback_R)
DllCall("opencv_world455.dll\cvCreateTrackbar", "Astr", "G", "Astr", "Image", "ptr", &g, "int", 255,"ptr", callback_G)
DllCall("opencv_world455.dll\cvCreateTrackbar", "Astr", "B", "Astr", "Image", "ptr", &b, "int", 255,"ptr", callback_B)
TheFunc_R(v_a, v_b){
    global sR := NumGet(r, 0, "int")
}
TheFunc_G(v_a, v_b){
    global sG := NumGet(g, 0, "int")
}
TheFunc_B(v_a, v_b){
    global sB := NumGet(b, 0, "int")
}
While true{
    sR := NumGet(r, 0, "int")
    sG := NumGet(g, 0, "int")
    sB := NumGet(b, 0, "int")
    cv.imshow("Image", img)
    loop, % rows{
    index_rows := A_Index
    loop, % cols{
        index_cols := A_Index
        img.Vec3b_set_at(index_rows - 1, index_cols - 1, ComArrayMake([sB, sG, sR]))
    }
}
}
cv.waitkey()
cv.destroyAllWindows()

 

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

 

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

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

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

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

 

v2H版示例:作为调色板的跟踪栏(由天黑请闭眼提供)

#Dllload lib
#DllLoad opencv_ahk.dll
#include <cv2>
#include <log>
SetWorkingDir A_ScriptDir
Persistent
;初始化opencv模块
cv := ObjFromPtr(DllCall('opencv_ahk.dll\opencv_init', 'ptr', DllCall(A_AhkPath '\ahkGetApi', 'ptr'), 'cdecl ptr'))
img := cv.Mat(400, 400, cv2.CV_8UC3, [0, 0, 0])
cv.namedWindow('image')
;创建一个改变颜色的轨迹栏
cv.createTrackbar('R','image', 255, rr := getpos.Bind("r"))
cv.createTrackbar('G','image', 255, gg := getpos.Bind("g"))
cv.createTrackbar('B','image', 255, bb := getpos.Bind("b"))
getpos(t, pos){
    static r := 0, g := 0, b := 0
    %t% := pos
    img.setTo(cv.MAT(1, 3, cv2.CV_8UC3, [b, g, r]))
    cv.imshow('image', img)
}
cv.waitKey()
cv.destroyAllWindows()

 

有错误请联系我改正!

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

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