- improved camera calibration
git-svn-id: http://moon:8086/svn/software/trunk/projects/opencv@320 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+14
-31
@@ -61,6 +61,8 @@ class FindObjects():
|
||||
objects = []
|
||||
temp_objects = []
|
||||
objectsCandIds = []
|
||||
|
||||
if hierachy.any():
|
||||
while count != -1:
|
||||
family = FindObjects.getFamily([], count, hierachy)
|
||||
|
||||
@@ -126,7 +128,9 @@ ap.add_argument("-r", "--framerate", type=int, default=30,
|
||||
ap.add_argument("-f", "--filename", type=str, default='piCamera',
|
||||
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")
|
||||
help="Whether calibration shall be performed")
|
||||
ap.add_argument("-u", "--use-calibration", type=str, default='off',
|
||||
help="Whether calibration shall be used")
|
||||
args = vars(ap.parse_args())
|
||||
|
||||
videoFile = args["filename"]
|
||||
@@ -138,7 +142,7 @@ if videoFile == "piCamera":
|
||||
from PiVideoStream import PiVideoStream
|
||||
from picamera.array import PiRGBArray
|
||||
from picamera import PiCamera
|
||||
vs = PiVideoStream(resolution=(2*width,2*height), framerate=framerate).start()
|
||||
vs = PiVideoStream(resolution=(width,height), framerate=framerate).start()
|
||||
time.sleep(5.0)
|
||||
else:
|
||||
vs = cv2.VideoCapture(videoFile)
|
||||
@@ -161,54 +165,34 @@ if args["calibrate"] == 'on':
|
||||
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, :]
|
||||
ref_color = cv2.mean(Z[int(height/2-8):int(height/2+8), int(width/2-8):int(width/2+8), :])
|
||||
print (ref_color)
|
||||
|
||||
for c in range (0, 3):
|
||||
lens_corr[:,:,c] = cv2.divide(ref_color[c], Z[:,:,c])
|
||||
lens_corr = cv2.divide(ref_color, Z)
|
||||
|
||||
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)
|
||||
cv2.imwrite("lens_corr.png", np.uint8(lens_corr*127.0), params)
|
||||
|
||||
sys.exit()
|
||||
|
||||
|
||||
frame = np.ones((height, width, 3), np.float32)
|
||||
lens_corr = np.float32(cv2.imread("lens_corr.png"))
|
||||
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"]:
|
||||
# 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]
|
||||
frame = vs.read()
|
||||
else:
|
||||
ret, frame8 = vs.read()
|
||||
ret, frame = 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
|
||||
if args["use_calibration"] == 'on':
|
||||
frame = np.uint8(cv2.multiply(lens_corr, np.float32(frame)))
|
||||
|
||||
kernel = np.ones((3,3),np.uint8)
|
||||
frame_dilated = cv2.dilate(frame,kernel,iterations = 1)
|
||||
@@ -284,7 +268,6 @@ while fps._numFrames < args["num_frames"]:
|
||||
print("Found " + str(numColorClasses) + " color classes")
|
||||
|
||||
|
||||
cv2.imshow('Raw',frame8)
|
||||
cv2.imshow('Corrected', frame)
|
||||
cv2.imshow('Contours', frame_dilated)
|
||||
cv2.imshow('Colors', img1_colors)
|
||||
|
||||
Reference in New Issue
Block a user