diff options
| author | Derric Williams <derricw@alleninstitute.org> | 2014-09-22 11:39:59 -0700 |
|---|---|---|
| committer | Derric Williams <derricw@alleninstitute.org> | 2014-09-22 11:39:59 -0700 |
| commit | e482e37793ff32b3d846acf8e0533ba284b1191e (patch) | |
| tree | 2bb745b45770d0f62d17d271bae63ea90b8d09de | |
| parent | 6aebd5c04313f3250c7b0b2b93410034220e7330 (diff) | |
| download | pymba-e482e37793ff32b3d846acf8e0533ba284b1191e.tar.gz pymba-e482e37793ff32b3d846acf8e0533ba284b1191e.zip | |
OpenCV Color Liveview example.
| -rw-r--r-- | pymba/tests/opencv_liveview_example.py | 5 | ||||
| -rw-r--r-- | pymba/tests/opencv_liveview_example_color.py | 92 | ||||
| -rw-r--r-- | pymba/vimbaframe.py | 11 | ||||
| -rw-r--r-- | setup.py | 1 |
4 files changed, 101 insertions, 8 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 964917b..ffa9e09 100644 --- a/pymba/vimbaframe.py +++ b/pymba/vimbaframe.py @@ -5,23 +5,26 @@ from vimbadll import VimbaDLL from vimbadll import VimbaC_MemoryBlock from ctypes import * -#map pixel formats to bytes per pixel. +""" +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, + "Mono12Packed": 1.5, # ? "Mono14": 2, "Mono16": 2, "RGB8Packed": 3, "BGR8Packed": 3, "RGBA8Packed": 4, "BGRA8Packed": 4, - "YUV411Packed": 4/3.0, + "YUV411Packed": 4/3.0, # ? "YUV422Packed": 2, "YUV444Packed": 3, "BayerRG8": 1, "BayerRG12": 2, - "BayerGR12Packed": 1.5, + "BayerGR12Packed": 1.5, # ? } @@ -25,5 +25,4 @@ setup(name="pymba", packages=['pymba', 'pymba.tests'], zip_safe=False, requires=['cv2', 'cv', 'numpy', 'scipy', 'pygame', 'pil', 'svgwrite'], - ) |
