首页 > 其他分享 >AHK调用opencv(八)作为调色板的跟踪栏

AHK调用opencv(八)作为调色板的跟踪栏

时间:2022-10-12 10:12:13浏览次数:84  
标签:int AHK global 调色板 cv opencv dll ptr

#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()

天黑版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
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。

标签:int,AHK,global,调色板,cv,opencv,dll,ptr
From: https://www.cnblogs.com/ff888/p/16783532.html

相关文章