- improved
git-svn-id: http://moon:8086/svn/software/trunk/projects/opencv@323 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+21
-12
@@ -14,8 +14,24 @@ class PiVideoStream:
|
||||
self.camera.exposure_mode = 'auto'
|
||||
# self.camera.image_effect = 'colorbalance'
|
||||
# self.camera.image_effect_params = (0,1,1,1,0,0)
|
||||
self.camera.exposure_mode = 'auto'
|
||||
self.camera.awb_mode = 'off'
|
||||
self.camera.awb_gains = (1.5, 1.5)
|
||||
# self.camera.analog_gain = 1.75
|
||||
# self.camera.digital_gain = 1.00
|
||||
self.rawCapture = PiRGBArray(self.camera, size=resolution)
|
||||
self.stream = self.camera.capture_continuous(self.rawCapture,
|
||||
format="bgr", use_video_port=True)
|
||||
|
||||
# initialize the frame and the variable used to indicate
|
||||
# if the thread should be stopped
|
||||
self.frame = None
|
||||
self.stopped = False
|
||||
self.fps = None
|
||||
self.thread = None
|
||||
self.startup = True
|
||||
|
||||
def printSettings(self):
|
||||
awb_gains = self.camera.awb_gains
|
||||
print ("sensor_mode : " + str(self.camera.sensor_mode))
|
||||
print ("resolution : " + str(self.camera.resolution))
|
||||
@@ -38,18 +54,6 @@ class PiVideoStream:
|
||||
print ("image_effect_params : " + str(self.camera.image_effect_params))
|
||||
print ("sharpness : " + str(self.camera.sharpness))
|
||||
|
||||
self.rawCapture = PiRGBArray(self.camera, size=resolution)
|
||||
self.stream = self.camera.capture_continuous(self.rawCapture,
|
||||
format="bgr", use_video_port=True)
|
||||
|
||||
# initialize the frame and the variable used to indicate
|
||||
# if the thread should be stopped
|
||||
self.frame = None
|
||||
self.stopped = False
|
||||
self.fps = None
|
||||
self.thread = None
|
||||
self.startup = True
|
||||
|
||||
def start(self):
|
||||
# start the thread to read frames from the video stream
|
||||
self.thread = Thread(target=self.update, args=())
|
||||
@@ -59,6 +63,11 @@ class PiVideoStream:
|
||||
def update(self):
|
||||
# keep looping infinitely until the thread is stopped
|
||||
for f in self.stream:
|
||||
if self.camera.exposure_mode == 'auto':
|
||||
if self.camera.analog_gain > 1.75 and self.camera.digital_gain == 1.0:
|
||||
self.camera.exposure_mode = 'off'
|
||||
self.printSettings()
|
||||
|
||||
if self.startup:
|
||||
self.fps = FPS().start()
|
||||
self.startup = False
|
||||
|
||||
+26
-25
@@ -62,7 +62,8 @@ class FindObjects():
|
||||
temp_objects = []
|
||||
objectsCandIds = []
|
||||
|
||||
if hierachy is not None:
|
||||
try:
|
||||
if hierachy.any():
|
||||
while count != -1:
|
||||
family = FindObjects.getFamily([], count, hierachy)
|
||||
|
||||
@@ -111,6 +112,8 @@ class FindObjects():
|
||||
self.meanThickness = int(abs(obj[0]['diameter'] - obj[1]['diameter'])/2)
|
||||
|
||||
objects.append({'thickness' : self.meanThickness, 'members' : obj})
|
||||
except:
|
||||
pass
|
||||
|
||||
return objects
|
||||
|
||||
@@ -175,15 +178,18 @@ if args["calibrate"] == 'on':
|
||||
params.append(0)
|
||||
|
||||
cv2.imwrite("lens_corr.png", np.uint8(lens_corr*127.0), params)
|
||||
cv2.imwrite("lens_shot.png", frame, params)
|
||||
|
||||
sys.exit()
|
||||
fps.stop()
|
||||
if videoFile == "piCamera":
|
||||
vs.stop()
|
||||
|
||||
else:
|
||||
frame = np.ones((height, width, 3), np.float32)
|
||||
lens_corr = np.float32(cv2.imread("lens_corr.png"))/128.0
|
||||
|
||||
frame = np.ones((height, width, 3), np.float32)
|
||||
lens_corr = np.float32(cv2.imread("lens_corr.png"))/140.0
|
||||
|
||||
# loop over some frames...this time using the threaded stream
|
||||
while fps._numFrames < args["num_frames"]:
|
||||
# loop over some frames...this time using the threaded stream
|
||||
while fps._numFrames < args["num_frames"]:
|
||||
# grab the frame from the threaded video stream
|
||||
|
||||
if videoFile == "piCamera":
|
||||
@@ -203,9 +209,9 @@ while fps._numFrames < args["num_frames"]:
|
||||
img1_canny = cv2.Canny(gray_blurred, 100, 50)
|
||||
|
||||
# Thresholding
|
||||
# ret,img1_thr = cv2.threshold(gray_blurred,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
|
||||
# img1_thr = cv2.adaptiveThreshold(gray_blurred,255,cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY,11,2)
|
||||
# img1_thr = cv2.adaptiveThreshold(gray_blurred,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,11,2)
|
||||
# ret,img1_thr = cv2.threshold(gray_blurred,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
|
||||
# img1_thr = cv2.adaptiveThreshold(gray_blurred,255,cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY,11,2)
|
||||
# img1_thr = cv2.adaptiveThreshold(gray_blurred,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,11,2)
|
||||
|
||||
# Contours
|
||||
(_, contours, hierachy) = cv2.findContours(img1_canny.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
|
||||
@@ -214,7 +220,7 @@ while fps._numFrames < args["num_frames"]:
|
||||
|
||||
objects = findObjects.find(contours, hierachy)
|
||||
|
||||
# print (ids)
|
||||
# print (ids)
|
||||
|
||||
img1_objects = frame.copy()
|
||||
img1_colors = np.zeros((height,width,3), np.uint8)
|
||||
@@ -240,7 +246,7 @@ while fps._numFrames < args["num_frames"]:
|
||||
mean_color = cv2.mean(roi)
|
||||
img1_colors = cv2.circle(img1_colors,(int(pos[0]),int(pos[1])),int(diameter/2),mean_color,-1)
|
||||
beads.append({'pos' : pos, 'diameter' : diameter, 'color' : [mean_color[0]/255, mean_color[1]/255, mean_color[2]/255]})
|
||||
# img1_objects = cv2.circle(img1_objects,member['pos'],int(diameter/2),(255,255,255),thickness)
|
||||
# img1_objects = cv2.circle(img1_objects,member['pos'],int(diameter/2),(255,255,255),thickness)
|
||||
else:
|
||||
img1_objects = cv2.rectangle(img1_objects,(x,y),(x+w,y+h),(0,0,255),2)
|
||||
|
||||
@@ -276,26 +282,24 @@ while fps._numFrames < args["num_frames"]:
|
||||
if videoFile == "piCamera":
|
||||
cv2.waitKey(1)
|
||||
else:
|
||||
# cv2.waitKey(0)
|
||||
# cv2.waitKey(0)
|
||||
cv2.waitKey(int(1000.0/framerate))
|
||||
|
||||
|
||||
# update the FPS counter
|
||||
fps.update()
|
||||
|
||||
# stop the timer and display FPS information
|
||||
fps.stop()
|
||||
if videoFile == "piCamera":
|
||||
# stop the timer and display FPS information
|
||||
fps.stop()
|
||||
if videoFile == "piCamera":
|
||||
vs.stop()
|
||||
|
||||
print("[INFO] elasped time: {:.2f}".format(fps.elapsed()))
|
||||
print("[INFO] approx. FPS: {:.2f}".format(fps.fps()))
|
||||
if videoFile == "piCamera":
|
||||
print("[INFO] elasped time: {:.2f}".format(fps.elapsed()))
|
||||
print("[INFO] approx. FPS: {:.2f}".format(fps.fps()))
|
||||
if videoFile == "piCamera":
|
||||
print("[INFO] Camera : elasped time: {:.2f}".format(vs.getfps().elapsed()))
|
||||
print("[INFO] Camera: approx. FPS: {:.2f}".format(vs.getfps().fps()))
|
||||
|
||||
if numColorClasses:
|
||||
|
||||
# Output stats
|
||||
findObjects.printStats()
|
||||
|
||||
@@ -318,7 +322,7 @@ if numColorClasses:
|
||||
|
||||
# Define criteria = ( type, max_iter, epsilon )
|
||||
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.1)
|
||||
ret,label,center=cv2.kmeans(np.float32(plotColors), numColorClasses, None, criteria, 10, cv2.KMEANS_PP_CENTERS)
|
||||
ret,label,center=cv2.kmeans(Z,numColorClasses,None,criteria,10,cv2.KMEANS_PP_CENTERS)
|
||||
|
||||
print (center)
|
||||
|
||||
@@ -341,9 +345,6 @@ if numColorClasses:
|
||||
|
||||
plt.show()
|
||||
|
||||
else:
|
||||
print("Sorry, no colors have been detected")
|
||||
|
||||
# do a bit of cleanup
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user