Browse files

small debayer improvements

  • Loading branch information...
1 parent ebed4a8 commit 61638937793e860f97c0e948e4a7a4d8cdd7114f @tridge committed Dec 14, 2011
Showing with 11 additions and 10 deletions.
  1. +7 −8 camera/debayer.py
  2. +4 −2 camera/util.py
View
15 camera/debayer.py
@@ -26,7 +26,7 @@ def debayer(filename):
cv.CvtColor(img8, color_img, cv.CV_BayerGR2BGR)
cv.ShowImage('Bayer', color_img)
- return color_img
+ return (color_img, pgm)
def mouse_event(event, x, y, flags, data):
'''called on mouse events'''
@@ -42,11 +42,9 @@ def mouse_event(event, x, y, flags, data):
def change_image(i):
'''show image idx'''
- global idx, image
+ global idx
idx = i
- image = debayer(args[idx])
- cv.ShowImage('Bayer', image)
- return image
+ return debayer(args[idx])
def show_images(args):
'''show all images'''
@@ -61,10 +59,11 @@ def show_images(args):
pgm = None
while True:
print(args[idx])
- image = change_image(idx)
+ (image, pgm) = change_image(idx)
oldidx = idx
newidx = util.key_menu(oldidx, len(args), image,
- '%s.png' % args[idx][:-4])
+ '%s.png' % args[idx][:-4],
+ pgm=pgm)
idx += (newidx - oldidx)
cv.SetTrackbarPos('Image', 'Bayer', idx)
cv.DestroyWindow('Bayer')
@@ -74,7 +73,7 @@ def convert_images(args):
for f in args:
png = f[:-4] + '.png'
print("Saving %s" % png)
- img = debayer(f)
+ (img, pgm) = debayer(f)
cv.SaveImage(png, img)
if opts.batch:
View
6 camera/util.py
@@ -40,12 +40,12 @@ def __init__(self, filename):
else:
rawdata = numpy.memmap(filename, dtype='uint16', mode='c', order='C', shape=(960,1280), offset=ofs)
self.img = cv.CreateImageHeader((1280, 960), 16, 1)
-
self.rawdata = rawdata.copy()
+ del(rawdata)
self.array = self.rawdata.byteswap(True)
cv.SetData(self.img, self.array.tostring(), self.array.dtype.itemsize*1*1280)
-def key_menu(i, n, image, filename):
+def key_menu(i, n, image, filename, pgm=None):
'''simple keyboard menu'''
while True:
key = cv.WaitKey()
@@ -58,6 +58,8 @@ def key_menu(i, n, image, filename):
if key == 's':
print("Saving %s" % filename)
cv.SaveImage(filename, image)
+ if key == 'c' and pgm is not None:
+ print("Comment: %s" % pgm.comment)
if key in ['n', '\n', ' ']:
if i == n-1:
print("At last image")

0 comments on commit 6163893

Please sign in to comment.