我正在尝试保存由轨迹栏修改的图像。当我尝试保存它(使用imwrite
)时,它只保存在轨迹栏修改之前的图像。下面的代码中没有显示,但我尝试在foo
函数中使用imwrite
,但没有成功。我还尝试从foo
函数返回图像和getTrackbarPos
,但这两个值都是未修改的输入
import cv2
def foo(val):
thresholdVal = cv2.getTrackbarPos('trackbar','window')
_, dst = cv2.threshold(image, thresholdVal, 255, cv2.THRESH_BINARY)
cv2.imshow('window',dst)
image = cv2.imread('img.jpg')
cv2.namedWindow('window')
cv2.createTrackbar('trackbar','window',0,255,foo)
foo(0)
cv2.waitKey(0)
cv2.destroyAllWindows
只需在脚本录制结束时添加一个无限循环。例如,按s时,保存当前
dst
图像。您需要另一个键作为退出循环的指示器,例如使用q。然后foo
方法中的dst
映像需要是全局的,以便后面的无限循环可以访问下面是一些代码:
thresholdVal
变量在这里也需要是全局变量,因为我在图像文件名中使用它的值相关问题 更多 >
编程相关推荐