I am running some code called bcf.py it is very long and convoluted, but in short, it extracts 300 feature points from each image from a group of folders. So potentially there could be hundreds of images.
When I go to run the script, everything works except I have to keep pressing the return button to extract all the feature points and repeat this button pressing for every image, which is frustrating.
Why does it do this, and how would I fix it? The goal is to press the wait key once and extract the features.
Thank you
I do not know what this is called to be able to search for an answer.
def _svm_classify_test(self):
clf = self._load_classifier()
label_to_cls = self._load_label_to_class_mapping()
testing_data = []
labels = []
for (cls, idx) in self.data.keys():
testing_data.append(self.data[(cls, idx)]['spp_descriptor'])
labels.append(hash(cls))
predictions = clf.predict(testing_data)
correct = 0
for (i, label) in enumerate(labels):
if predictions[i] == label:
correct += 1
else:
print("Mistook %s for %s" % (label_to_cls[label], label_to_cls[predictions[i]]))
print("Correct: %s out of %s (Accuracy: %.2f%%)" % (correct, len(predictions), 100. * correct / len(predictions)))
def show(self, image):
cv2.imshow('image', image)
_ = cv2.waitKey()
The goal is to press the wait key once and automatically runs through all the images and extract the features.
The function cv.waitKey([, delay])
as it is explained in the documentation, it may take a value which you can consider as timeout. That means, you can pass a 10 and it will block the function for 10 milliseconds for a keyboard input.
For your case, I do not see where in the code you use your function show
so I can't know exactly how you should do it to have that behaviour, but as a pseudocode for you to get an idea, it will be something like:
filenames = [] #lets assume your filenames are here
for f in filenames:
img = cv2.imread(f)
cv2.imshow("image", img)
cv2.waitKey(10)
If you want a pause at the beginning you can do an imshow outside the loop and a waitkey with 0 after it. Also, you can play with the amount of time, like 5000 to display it for 5 seconds before continuing.
But if it takes too long to process you may consider putting the imshow part in a thread, since the window maybe unresponsive after the waitKey while it waits for the feature extraction process to finish. Also, it may be good to add something like 'q' to quit the app or something.... These are just some suggestions :)