- added cam calib
git-svn-id: http://moon:8086/svn/software/trunk/projects/opencv@319 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+23
-17
@@ -12,25 +12,31 @@ class PiVideoStream:
|
|||||||
self.camera.resolution = resolution
|
self.camera.resolution = resolution
|
||||||
self.camera.framerate = framerate
|
self.camera.framerate = framerate
|
||||||
self.camera.exposure_mode = 'auto'
|
self.camera.exposure_mode = 'auto'
|
||||||
|
# self.camera.image_effect = 'colorbalance'
|
||||||
|
# self.camera.image_effect_params = (0,1,1,1,0,0)
|
||||||
|
|
||||||
|
|
||||||
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))
|
||||||
print ("framerate : " + str(self.camera.framerate))
|
print ("framerate : " + str(self.camera.framerate))
|
||||||
print ("awb_mode : " + str(self.camera.awb_mode))
|
print ("awb_mode : " + str(self.camera.awb_mode))
|
||||||
print ("awb_gains : " + str((float(awb_gains[0]), float(awb_gains[1]))))
|
print ("awb_gains : " + str((float(awb_gains[0]), float(awb_gains[1]))))
|
||||||
print ("analog_gain : " + str(float(self.camera.analog_gain)))
|
print ("analog_gain : " + str(float(self.camera.analog_gain)))
|
||||||
print ("digital_gain : " + str(float(self.camera.digital_gain)))
|
print ("digital_gain : " + str(float(self.camera.digital_gain)))
|
||||||
print ("iso : " + str(self.camera.iso))
|
print ("iso : " + str(self.camera.iso))
|
||||||
print ("brightness : " + str(self.camera.brightness))
|
print ("brightness : " + str(self.camera.brightness))
|
||||||
print ("contrast : " + str(self.camera.contrast))
|
print ("contrast : " + str(self.camera.contrast))
|
||||||
print ("saturation : " + str(self.camera.saturation))
|
print ("saturation : " + str(self.camera.saturation))
|
||||||
print ("exposure_mode : " + str(self.camera.exposure_mode))
|
print ("exposure_mode : " + str(self.camera.exposure_mode))
|
||||||
print ("exposure_speed: " + str(self.camera.exposure_speed))
|
print ("exposure_speed : " + str(self.camera.exposure_speed))
|
||||||
print ("shutter_speed : " + str(self.camera.shutter_speed))
|
print ("exposure_compensation: " + str(self.camera.exposure_compensation))
|
||||||
print ("meter_mode : " + str(self.camera.meter_mode))
|
print ("shutter_speed : " + str(self.camera.shutter_speed))
|
||||||
print ("image_effect : " + str(self.camera.image_effect))
|
print ("meter_mode : " + str(self.camera.meter_mode))
|
||||||
print ("sharpness : " + str(self.camera.sharpness))
|
print ("color_effects : " + str(self.camera.color_effects))
|
||||||
|
print ("image_effect : " + str(self.camera.image_effect))
|
||||||
|
print ("image_effect_params : " + str(self.camera.image_effect_params))
|
||||||
|
print ("sharpness : " + str(self.camera.sharpness))
|
||||||
|
|
||||||
self.rawCapture = PiRGBArray(self.camera, size=resolution)
|
self.rawCapture = PiRGBArray(self.camera, size=resolution)
|
||||||
self.stream = self.camera.capture_continuous(self.rawCapture,
|
self.stream = self.camera.capture_continuous(self.rawCapture,
|
||||||
|
|||||||
+61
-7
@@ -3,6 +3,7 @@ from __future__ import print_function
|
|||||||
|
|
||||||
from imutils.video import FPS
|
from imutils.video import FPS
|
||||||
|
|
||||||
|
import sys
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import argparse
|
import argparse
|
||||||
import time
|
import time
|
||||||
@@ -83,7 +84,7 @@ class FindObjects():
|
|||||||
perimeter = cv2.arcLength(contours[member['id']], True)
|
perimeter = cv2.arcLength(contours[member['id']], True)
|
||||||
pi = 3.14159265359
|
pi = 3.14159265359
|
||||||
Q = 0
|
Q = 0
|
||||||
if (perimeter > 0):
|
if (area > 10):
|
||||||
Q = 4*pi*area/(perimeter*perimeter)
|
Q = 4*pi*area/(perimeter*perimeter)
|
||||||
|
|
||||||
if Q > 0.7:
|
if Q > 0.7:
|
||||||
@@ -124,6 +125,8 @@ ap.add_argument("-r", "--framerate", type=int, default=30,
|
|||||||
help="# of frames to loop over for FPS test")
|
help="# of frames to loop over for FPS test")
|
||||||
ap.add_argument("-f", "--filename", type=str, default='piCamera',
|
ap.add_argument("-f", "--filename", type=str, default='piCamera',
|
||||||
help="Whether or not frames should be displayed")
|
help="Whether or not frames should be displayed")
|
||||||
|
ap.add_argument("-c", "--calibrate", type=str, default='off',
|
||||||
|
help="Whether or not frames should be displayed")
|
||||||
args = vars(ap.parse_args())
|
args = vars(ap.parse_args())
|
||||||
|
|
||||||
videoFile = args["filename"]
|
videoFile = args["filename"]
|
||||||
@@ -135,7 +138,7 @@ if videoFile == "piCamera":
|
|||||||
from PiVideoStream import PiVideoStream
|
from PiVideoStream import PiVideoStream
|
||||||
from picamera.array import PiRGBArray
|
from picamera.array import PiRGBArray
|
||||||
from picamera import PiCamera
|
from picamera import PiCamera
|
||||||
vs = PiVideoStream(resolution=(width,height), framerate=framerate).start()
|
vs = PiVideoStream(resolution=(2*width,2*height), framerate=framerate).start()
|
||||||
time.sleep(5.0)
|
time.sleep(5.0)
|
||||||
else:
|
else:
|
||||||
vs = cv2.VideoCapture(videoFile)
|
vs = cv2.VideoCapture(videoFile)
|
||||||
@@ -150,14 +153,63 @@ findObjects = FindObjects()
|
|||||||
beadColors = []
|
beadColors = []
|
||||||
numColorClasses = 0
|
numColorClasses = 0
|
||||||
|
|
||||||
# loop over some frames...this time using the threaded stream
|
if args["calibrate"] == 'on':
|
||||||
while fps._numFrames < args["num_frames"]:
|
lens_corr = np.ones((height, width, 3), np.float32)
|
||||||
# grab the frame from the threaded video stream
|
|
||||||
if videoFile == "piCamera":
|
if videoFile == "piCamera":
|
||||||
frame = vs.read()
|
frame = vs.read()
|
||||||
else:
|
else:
|
||||||
ret, frame = vs.read()
|
ret, frame = vs.read()
|
||||||
|
|
||||||
|
Z = np.float32(frame)
|
||||||
|
print (frame.dtype)
|
||||||
|
print (frame.shape)
|
||||||
|
print (lens_corr.dtype)
|
||||||
|
print (lens_corr.shape)
|
||||||
|
print (Z.dtype)
|
||||||
|
print (Z.shape)
|
||||||
|
ref_color = Z[height/2, width/2, :]
|
||||||
|
print (ref_color)
|
||||||
|
|
||||||
|
for c in range (0, 3):
|
||||||
|
lens_corr[:,:,c] = cv2.divide(ref_color[c], Z[:,:,c])
|
||||||
|
|
||||||
|
params = list()
|
||||||
|
params.append(cv2.IMWRITE_PNG_COMPRESSION)
|
||||||
|
params.append(0)
|
||||||
|
|
||||||
|
for c in range (0, 3):
|
||||||
|
lens_corr[:,:,c] = cv2.multiply(128, lens_corr[:,:,c])
|
||||||
|
cv2.imwrite("lens_corr.png", np.uint8(lens_corr), params)
|
||||||
|
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
frame = np.ones((height, width, 3), np.float32)
|
||||||
|
lens_corr = np.float32(cv2.imread("lens_corr.png"))
|
||||||
|
|
||||||
|
# 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":
|
||||||
|
frame8 = vs.read()[int(height/2):int(height/2+height), int(width/2):int(width/2)+width]
|
||||||
|
else:
|
||||||
|
ret, frame8 = vs.read()
|
||||||
|
|
||||||
|
if 0:
|
||||||
|
frame32 = np.float32(frame8)
|
||||||
|
print (frame.dtype)
|
||||||
|
print (frame.shape)
|
||||||
|
print (lens_corr.dtype)
|
||||||
|
print (lens_corr.shape)
|
||||||
|
|
||||||
|
for c in range (0, 3):
|
||||||
|
frame32[:,:,c] = cv2.multiply(lens_corr[:,:,c], frame32[:,:,c], 1.0/255)
|
||||||
|
|
||||||
|
frame = np.uint8(frame32)
|
||||||
|
else:
|
||||||
|
frame = frame8
|
||||||
|
|
||||||
kernel = np.ones((3,3),np.uint8)
|
kernel = np.ones((3,3),np.uint8)
|
||||||
frame_dilated = cv2.dilate(frame,kernel,iterations = 1)
|
frame_dilated = cv2.dilate(frame,kernel,iterations = 1)
|
||||||
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
|
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
|
||||||
@@ -231,7 +283,9 @@ while fps._numFrames < args["num_frames"]:
|
|||||||
numColorClasses = len(colorClasses)
|
numColorClasses = len(colorClasses)
|
||||||
print("Found " + str(numColorClasses) + " color classes")
|
print("Found " + str(numColorClasses) + " color classes")
|
||||||
|
|
||||||
# cv2.imshow('Thresholded',img1_thr)
|
|
||||||
|
cv2.imshow('Raw',frame8)
|
||||||
|
cv2.imshow('Corrected', frame)
|
||||||
cv2.imshow('Contours', frame_dilated)
|
cv2.imshow('Contours', frame_dilated)
|
||||||
cv2.imshow('Colors', img1_colors)
|
cv2.imshow('Colors', img1_colors)
|
||||||
cv2.imshow('Canny',img1_canny)
|
cv2.imshow('Canny',img1_canny)
|
||||||
@@ -279,7 +333,7 @@ Z = np.float32(plotColors)
|
|||||||
|
|
||||||
# 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(Z,10,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)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user