aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormorefigs <morefigs@gmail.com>2014-09-23 07:40:30 +1000
committermorefigs <morefigs@gmail.com>2014-09-23 07:40:30 +1000
commit9b7a5641edba4a044e4508068f200a6157c22a0d (patch)
tree2bb745b45770d0f62d17d271bae63ea90b8d09de
parentf672513907c134db2794519fe79f5a4e1f8d6a44 (diff)
parente482e37793ff32b3d846acf8e0533ba284b1191e (diff)
downloadpymba-9b7a5641edba4a044e4508068f200a6157c22a0d.tar.gz
pymba-9b7a5641edba4a044e4508068f200a6157c22a0d.zip
Merge pull request #6 from derricw/master
Color Example and support for all color formats.
-rw-r--r--pymba/tests/opencv_liveview_example.py5
-rw-r--r--pymba/tests/opencv_liveview_example_color.py92
-rw-r--r--pymba/vimbaframe.py19
-rw-r--r--setup.py1
4 files changed, 110 insertions, 7 deletions
diff --git a/pymba/tests/opencv_liveview_example.py b/pymba/tests/opencv_liveview_example.py
index 1382d82..415f892 100644
--- a/pymba/tests/opencv_liveview_example.py
+++ b/pymba/tests/opencv_liveview_example.py
@@ -39,6 +39,7 @@ except:
#set pixel format
c0.PixelFormat="Mono8"
+#c0.ExposureTimeAbs=60000
frame = c0.getFrame()
frame.announceFrame()
@@ -57,7 +58,7 @@ while 1:
success = False
c0.runFeatureCommand("AcquisitionStart")
c0.runFeatureCommand("AcquisitionStop")
- frame.waitFrameCapture(100)
+ frame.waitFrameCapture(1000)
frame_data = frame.getBufferByteData()
if success:
img = np.ndarray(buffer=frame_data,
@@ -71,8 +72,6 @@ while 1:
print "Frames displayed: %i"%framecount
print "Frames dropped: %s"%droppedframes
break
- #del frame
-#print img
c0.endCapture()
diff --git a/pymba/tests/opencv_liveview_example_color.py b/pymba/tests/opencv_liveview_example_color.py
new file mode 100644
index 0000000..a13d56c
--- /dev/null
+++ b/pymba/tests/opencv_liveview_example_color.py
@@ -0,0 +1,92 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Mon Jul 07 14:59:03 2014
+
+@author: derricw
+
+Same as the other liveview example, but displays in color.
+
+Obviously you want to use a camera that has a color mode like BGR8Packed
+
+OpenCV is expecting color images to be in BGR8Packed by default. It can work
+ with other formats as well as convert one to the other, but this example
+ just uses its default behavior.
+
+"""
+
+from pymba import *
+import numpy as np
+import cv2
+import time
+import sys
+
+cv2.namedWindow("test")
+
+vimba = Vimba()
+vimba.startup()
+
+system = vimba.getSystem()
+
+system.runFeatureCommand("GeVDiscoveryAllOnce")
+time.sleep(0.2)
+
+camera_ids = vimba.getCameraIds()
+
+for cam_id in camera_ids:
+ print("Camera found: ", cam_id)
+
+c0 = vimba.getCamera(camera_ids[0])
+c0.openCamera()
+
+try:
+ #gigE camera
+ print("Packet size:", c0.GevSCPSPacketSize)
+ c0.StreamBytesPerSecond = 100000000
+ print("BPS:", c0.StreamBytesPerSecond)
+except:
+ #not a gigE camera
+ pass
+
+#set pixel format
+c0.PixelFormat = "BGR8Packed" # OPENCV DEFAULT
+time.sleep(0.2)
+
+frame = c0.getFrame()
+frame.announceFrame()
+
+c0.startCapture()
+
+framecount = 0
+droppedframes = []
+
+while 1:
+ try:
+ frame.queueFrameCapture()
+ success = True
+ except:
+ droppedframes.append(framecount)
+ success = False
+ c0.runFeatureCommand("AcquisitionStart")
+ c0.runFeatureCommand("AcquisitionStop")
+ frame.waitFrameCapture(1000)
+ frame_data = frame.getBufferByteData()
+ if success:
+ img = np.ndarray(buffer=frame_data,
+ dtype=np.uint8,
+ shape=(frame.height, frame.width, frame.pixel_bytes))
+ cv2.imshow("test", img)
+ framecount += 1
+ k = cv2.waitKey(1)
+ if k == 0x1b:
+ cv2.destroyAllWindows()
+ print("Frames displayed: %i" % framecount)
+ print("Frames dropped: %s" % droppedframes)
+ break
+
+
+c0.endCapture()
+c0.revokeAllFrames()
+
+c0.closeCamera()
+
+vimba.shutdown()
diff --git a/pymba/vimbaframe.py b/pymba/vimbaframe.py
index 9e92285..ffa9e09 100644
--- a/pymba/vimbaframe.py
+++ b/pymba/vimbaframe.py
@@ -5,14 +5,26 @@ from vimbadll import VimbaDLL
from vimbadll import VimbaC_MemoryBlock
from ctypes import *
-#map pixel formats to bytes per pixel. TODO: packed mono formats?
+"""
+Map pixel formats to bytes per pixel.
+ The packed formats marked with "?" have not been tested.
+"""
PIXEL_FORMATS = {
"Mono8": 1,
"Mono12": 2,
+ "Mono12Packed": 1.5, # ?
"Mono14": 2,
"Mono16": 2,
"RGB8Packed": 3,
"BGR8Packed": 3,
+ "RGBA8Packed": 4,
+ "BGRA8Packed": 4,
+ "YUV411Packed": 4/3.0, # ?
+ "YUV422Packed": 2,
+ "YUV444Packed": 3,
+ "BayerRG8": 1,
+ "BayerRG12": 2,
+ "BayerGR12Packed": 1.5, # ?
}
@@ -117,7 +129,8 @@ class VimbaFrame(object):
POINTER(c_ubyte * self.payloadSize))
# make array of c_ubytes from buffer
- array = (c_ubyte * (self.height*self.pixel_bytes) *
- (self.width*self.pixel_bytes)).from_address(addressof(data.contents))
+ array = (c_ubyte * int(self.height*self.pixel_bytes) *
+ int(self.width*self.pixel_bytes)).from_address(addressof(
+ data.contents))
return array
diff --git a/setup.py b/setup.py
index 1bb1bff..7456c93 100644
--- a/setup.py
+++ b/setup.py
@@ -25,5 +25,4 @@ setup(name="pymba",
packages=['pymba', 'pymba.tests'],
zip_safe=False,
requires=['cv2', 'cv', 'numpy', 'scipy', 'pygame', 'pil', 'svgwrite'],
-
)