0
pythonでopencv3.1としてcv2を操作する2.7.12。私が今行っている問題は、複数の命令セットに従っているにもかかわらず、すべて自分自身と同じ設定を使用しているか、少なくとも非常に似た設定を使用しているようです。私は主に、これらの2つの例、すなわちopenCV.orgとCodeGenerater's Blogspot tutorialに行きます。私はコールバック関数を作成するか、cv2.getTrackbarPos
を使うことを忘れませんでした。私はそれが私はそれを行う特定の順序や画像の表示ループに何か間違っている必要があります感じる。ここで私が持っているもので、それは最初のトラックバーの閾値と画像をdiaplaysが、トラックバーのコールバックで画像を更新しません:cv2 getTrackbarPosが機能しない
import cv2
#write simple callback function to pass trackbar position as *arg
def callback(*arg):
pass
#create display window for image
cv2.namedWindow('frame')
#read in image
img = cv2.imread(r'/home/Usr/Documents/Aerial-Images/images_with_targets/Flight_4/target_10.jpg',0)
#instantiate trackbar that goes in our named window and uses callback function
cv2.createTrackbar('thresh2','frame',5,15,callback)
#initialize thresholds
thresh1=11
thresh2=5
#loop really just runs until the escape key causes a break
while(True):
#sets threshold 2 to trackbar position
thresh2=cv2.getTrackbarPos('thresh2','frame')
#apply laplacian filter to ehance edge gradients
th = cv2.Laplacian(img,cv2.CV_8UC1)
#binarize image with adaptive threshold
th = cv2.adaptiveThreshold(th,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY_INV,thresh1,thresh2)
#show filtered image
cv2.imshow('frame',th)
#waits for escape key then breaks out of loop
if cv2.waitKey(0) & 0xFF == ord('q'):
break
#close our display window
cv2.destroyallwindows()