- 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.exposure_mode = 'auto'
|
||||||
# self.camera.image_effect = 'colorbalance'
|
# self.camera.image_effect = 'colorbalance'
|
||||||
# self.camera.image_effect_params = (0,1,1,1,0,0)
|
# 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
|
awb_gains = self.camera.awb_gains
|
||||||
print ("sensor_mode : " + str(self.camera.sensor_mode))
|
print ("sensor_mode : " + str(self.camera.sensor_mode))
|
||||||
print ("resolution : " + str(self.camera.resolution))
|
print ("resolution : " + str(self.camera.resolution))
|
||||||
@@ -38,18 +54,6 @@ class PiVideoStream:
|
|||||||
print ("image_effect_params : " + str(self.camera.image_effect_params))
|
print ("image_effect_params : " + str(self.camera.image_effect_params))
|
||||||
print ("sharpness : " + str(self.camera.sharpness))
|
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):
|
def start(self):
|
||||||
# start the thread to read frames from the video stream
|
# start the thread to read frames from the video stream
|
||||||
self.thread = Thread(target=self.update, args=())
|
self.thread = Thread(target=self.update, args=())
|
||||||
@@ -59,6 +63,11 @@ class PiVideoStream:
|
|||||||
def update(self):
|
def update(self):
|
||||||
# keep looping infinitely until the thread is stopped
|
# keep looping infinitely until the thread is stopped
|
||||||
for f in self.stream:
|
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:
|
if self.startup:
|
||||||
self.fps = FPS().start()
|
self.fps = FPS().start()
|
||||||
self.startup = False
|
self.startup = False
|
||||||
|
|||||||
+11
-10
@@ -62,7 +62,8 @@ class FindObjects():
|
|||||||
temp_objects = []
|
temp_objects = []
|
||||||
objectsCandIds = []
|
objectsCandIds = []
|
||||||
|
|
||||||
if hierachy is not None:
|
try:
|
||||||
|
if hierachy.any():
|
||||||
while count != -1:
|
while count != -1:
|
||||||
family = FindObjects.getFamily([], count, hierachy)
|
family = FindObjects.getFamily([], count, hierachy)
|
||||||
|
|
||||||
@@ -111,6 +112,8 @@ class FindObjects():
|
|||||||
self.meanThickness = int(abs(obj[0]['diameter'] - obj[1]['diameter'])/2)
|
self.meanThickness = int(abs(obj[0]['diameter'] - obj[1]['diameter'])/2)
|
||||||
|
|
||||||
objects.append({'thickness' : self.meanThickness, 'members' : obj})
|
objects.append({'thickness' : self.meanThickness, 'members' : obj})
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
return objects
|
return objects
|
||||||
|
|
||||||
@@ -175,12 +178,15 @@ if args["calibrate"] == 'on':
|
|||||||
params.append(0)
|
params.append(0)
|
||||||
|
|
||||||
cv2.imwrite("lens_corr.png", np.uint8(lens_corr*127.0), params)
|
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)
|
frame = np.ones((height, width, 3), np.float32)
|
||||||
lens_corr = np.float32(cv2.imread("lens_corr.png"))/140.0
|
lens_corr = np.float32(cv2.imread("lens_corr.png"))/128.0
|
||||||
|
|
||||||
# loop over some frames...this time using the threaded stream
|
# loop over some frames...this time using the threaded stream
|
||||||
while fps._numFrames < args["num_frames"]:
|
while fps._numFrames < args["num_frames"]:
|
||||||
@@ -294,8 +300,6 @@ if videoFile == "piCamera":
|
|||||||
print("[INFO] Camera : elasped time: {:.2f}".format(vs.getfps().elapsed()))
|
print("[INFO] Camera : elasped time: {:.2f}".format(vs.getfps().elapsed()))
|
||||||
print("[INFO] Camera: approx. FPS: {:.2f}".format(vs.getfps().fps()))
|
print("[INFO] Camera: approx. FPS: {:.2f}".format(vs.getfps().fps()))
|
||||||
|
|
||||||
if numColorClasses:
|
|
||||||
|
|
||||||
# Output stats
|
# Output stats
|
||||||
findObjects.printStats()
|
findObjects.printStats()
|
||||||
|
|
||||||
@@ -318,7 +322,7 @@ if numColorClasses:
|
|||||||
|
|
||||||
# Define criteria = ( type, max_iter, epsilon )
|
# Define criteria = ( type, max_iter, epsilon )
|
||||||
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.1)
|
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)
|
print (center)
|
||||||
|
|
||||||
@@ -341,9 +345,6 @@ if numColorClasses:
|
|||||||
|
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
else:
|
|
||||||
print("Sorry, no colors have been detected")
|
|
||||||
|
|
||||||
# do a bit of cleanup
|
# do a bit of cleanup
|
||||||
cv2.destroyAllWindows()
|
cv2.destroyAllWindows()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user