The problem is that it is slow and it makes the image smaller. Does anybody know how to access dc1394's demosaicing functions, and or use opencv or numpy to make this a bit faster?
Here is my code, (it's based mostly on one of the examples)
#
# This file is part of pydc1394.
#
# pydc1394 is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# pydc1394 is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with pydc1394. If not, see
# <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2009, 2010 by Holger Rapp <Holge...@gmx.net>
# and the pydc1394 contributors (see README File)
import sys
from time import sleep
from pydc1394 import DC1394Library, Camera
import Image
import matplotlib
l = DC1394Library()
cams = l.enumerate_cameras()
cam0_handle = cams[0]
print "Opening camera!"
cam0 = Camera(l, cam0_handle['guid'])
#those can be automated, the other are manual
try:
cam0.brightness.mode = 'auto'
cam0.exposure.mode = 'auto'
cam0.white_balance.mode = 'auto'
except AttributeError: # thrown if the camera misses one of the features
pass
for feat in cam0.features:
print "feat: %s (cam0): %s" % (feat,cam0.__getattribute__(feat).val)
#choose color mode
print cam0.modes
cam0.mode = cam0.modes[0]
if len(sys.argv) > 1:
cam0.start(interactive=False)
sleep(0.5) #let hardware start !
matrix = cam0.shot()
cam0.stop()
else:
cam0.start(interactive=True)
sleep(0.5) #let hardware start !
matrix = cam0.current_image
cam0.stop()
print "Shape:", matrix.shape
i = Image.fromarray(matrix)
i.save("mosaic.bmp")
print('demosaicing from RGGB format')
im = Image.new('RGB', (matrix.shape[1]/2, matrix.shape[0]/2))
px = im.load()
for y in range( 0, matrix.shape[0], 2):
for x in range( 0, matrix.shape[1], 2):
r = matrix[y][x]
g = matrix[y][x+1]/2 + matrix[y+1][x]/2
b = matrix[y+1][x+1]
px[x/2 , y/2] = (r,g,b)
print('saving' )
im.save('rgb.png')
--
You received this message because you are subscribed to the Google Groups "pydc1394" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydc1394+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
def demosaic_super_simple( m ):r = m[0::2, 0::2] #gets every other row and columng = (( m[0::2, 1::2]/2 + m[1::2, 0::2]/2)).clip(0,255)b = m[1::2, 1::2]ms = np.dstack([r,g,b])#stacks 3 2d arrays into one 3d arrayreturn ms