python 2.7 - cv2 getTrackbarPos not working -


working opencv3.1 cv2 in python 2.7.12. problem i'm having right that, though following multiple sets of instructions seem use same setup myself or @ least similar one. going these 2 examples: opencv.org , codegenerater's blogspot tutorial. did not forget make callback function or use cv2.gettrackbarpos. feel there must wrong specific order in or image display loop. here have, diaplays image initial trackbar threshold, not update image trackbar callback:

import cv2   #write simple callback function pass trackbar position *arg     def callback(*arg):      pass  #create display window 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 goes in our named window , uses callback function cv2.createtrackbar('thresh2','frame',5,15,callback)  #initialize thresholds thresh1=11 thresh2=5  #loop runs until escape key causes break while(true):      #sets threshold 2 trackbar position     thresh2=cv2.gettrackbarpos('thresh2','frame')        #apply laplacian filter ehance edge gradients     th = cv2.laplacian(img,cv2.cv_8uc1)     #binarize image 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 escape key breaks out of loop     if cv2.waitkey(0) & 0xff == ord('q'):         break   #close our display window      cv2.destroyallwindows() 

the answer quite simple really. upon viewing older code wrote, realized needed change wait key 0 1:

if cv2.waitkey(0) & 0xff == ord('q'):     break 

became

if cv2.waitkey(1) & 0xff == ord('q'):     break 

what did not see forgot camel case cv2.destroyallwindows, made me think display loop still running when not.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -