Skip to content

Commit

Permalink
Save, get image added
Browse files Browse the repository at this point in the history
  • Loading branch information
mbalatsko committed Oct 2, 2018
1 parent ce91964 commit 4006fe5
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 13 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,16 @@ To close OpenCV windows just push 'Q' on your keyboard. You don't have to launch
procedure with the image, just change wanted values and push the button. That's it!
![Basler OpenCV viewer](https://raw.githubusercontent.com/mbalatsko/pypylon-opencv-viewer/master/images/wiget.PNG)
![Basler OpenCV viewer](https://raw.githubusercontent.com/mbalatsko/pypylon-opencv-viewer/master/images/opened.PNG)

#### Save or get image from camera

In previous steps we set up camera features parameters using widgets. Now we can save camera image on disc or get
raw openCV image.

```python
# Save image
viewer.save_image('grabbed.png', path='~/Documents/images')

# Get grabbed image
img = viewer.get_image()
```
46 changes: 46 additions & 0 deletions pypylon_opencv_viewer/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,52 @@ def camera_configuration(**kwargs):
return
return camera_configuration

def save_image(self, filename, path='.'):
"""Saves grabbed image
Parameters
----------
filename : str
Filename of grabbed image
path : str
Path to saved image
Returns
-------
None
"""
if self._camera is None or not self._camera.IsOpen():
raise ValueError("Camera object {} is closed.".format(self._camera))

converter = pylon.ImageFormatConverter()
converter.OutputPixelFormat = pylon.PixelType_BGR8packed
converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned

grab_result = self._camera.GrabOne(5000)
image = converter.Convert(grab_result)
img = image.GetArray()
cv2.imwrite(path + '/' + filename, img)

def get_image(self):
"""Returns grabbed image
Returns
-------
openCV image
"""
if self._camera is None or not self._camera.IsOpen():
raise ValueError("Camera object {} is closed.".format(self._camera))

converter = pylon.ImageFormatConverter()
converter.OutputPixelFormat = pylon.PixelType_BGR8packed
converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned

grab_result = self._camera.GrabOne(5000)
image = converter.Convert(grab_result)
img = image.GetArray()
return img


def _resolve_widget_type(self, widget_type_name):
"""Converts widget type name into widget object
Expand Down
23 changes: 10 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,22 @@
setup(
name='pypylon-opencv-viewer',
packages=find_packages(),
version='1.0',
description='Easy to use Jupyter notebook interface connecting Basler Pylon images grabbing with openCV image processing.'
' Allows to specify interactive Jupyter widgets to manipulate Basler camera features values, grab camera image and at'
'once get an OpenCV window on which raw camera output is displayed or you can specify an image processing function,'
'which takes on the input raw camera output image and display your own output.',
long_description=long_description,
version='1.0.1',
description='Save on disc added, Get image added',
long_description=long_description,
long_description_content_type='text/markdown',
license='MIT License',
author='Maksym Balatsko',
author_email='mbalatsko@gmail.com',
url='https://github.com/mbalatsko/pypylon-opencv-viewer',
download_url='https://github.com/mbalatsko/pypylon-opencv-viewer/archive/1.0.tar.gz',
download_url='https://github.com/mbalatsko/pypylon-opencv-viewer/archive/1.0.1.tar.gz',
install_requires=[
'opencv-python',
'jupyter',
'pypylon',
'ipywidgets',
'ipython'
],
'opencv-python',
'jupyter',
'pypylon',
'ipywidgets',
'ipython'
],
keywords=['basler', 'pypylon', 'opencv', 'jypyter', 'pypylon viewer', 'opencv pypylon'],
classifiers=[
'Programming Language :: Python :: 3',
Expand Down

0 comments on commit 4006fe5

Please sign in to comment.