Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added threading for processing the blurriness value
- Loading branch information
1 parent
5c88419
commit f365047
Showing
2 changed files
with
38 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import cv2 | ||
from threading import Thread | ||
from Queue import Queue | ||
|
||
class ProcessFocus(Thread): | ||
"""Work out a focus value for a given frame""" | ||
|
||
def __init__(self): | ||
Thread.__init__(self) | ||
self.queue = Queue() | ||
self.focus = -1 | ||
self.setDaemon(True) # terminate on exit | ||
|
||
def variance_of_laplacian(self, image): | ||
# compute the Laplacian of the image and then return the focus | ||
# measure, which is simply the variance of the Laplacian | ||
return cv2.Laplacian(image, cv2.CV_64F).var() | ||
|
||
def run(self): | ||
frame = None | ||
while True: | ||
try: | ||
frame = self.queue.get() | ||
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | ||
self.focus = self.variance_of_laplacian(gray) | ||
except: | ||
print("ERROR in ProcessFocus") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters