Python is a programming language you can use to create your machine vision program. In this article we show you how to download, install and use a python sample to acquire images. We are using the program PyCharm.
Download and install required software:
First follow this guide to make sure you have our windows SDK installed and you are able to acquire images from the camera using it:
https://www.get-cameras.com/QuickStart-5-steps-to-easily-install-a-machine-vision-camera-and-acquire-an-image
After installing the Daheng SDK several samples are provided, those are placed in the directory
C:\Program Files\Daheng Imaging\GalaxySDK\Samples\Python SDK
Download python 3.8 executable installer and install it.
You can download Python 3.8 executable installer at the address below. Please make sure you select the
“Windows x86-64 executable installer”
https://www.python.org/downloads/release/python-380/
Once the file is downloaded, double click to open it. At the following pop-up window, make sure the 2 options at the bottom are flagged:
“Install launcher for all users (recommended) and Add Python 3.8 to PATH”.
Click “Install NOW”
Close the next window, Python is now installed.
Install PYCHARM, the program used to run Python scripts.
Download and install PyCharm:
https://www.jetbrains.com/pycharm/download/#section=windows
Make sure you download the community (free) edition of PyCharm.
Once downloaded, double click on the file to run the installer.
When you see the window as shown below, click on next.
After that, the second window will pop up. If you want, you can change the installation location. When the location is good, click on next.
On the following page make sure the correct options are selected:
- 64-bit launcher
- Add launchers dir to the PATH
- .py
If these options are selected, continue by clicking
"next"
Click on Install. When the installation is completed reboot the pc.
After reboot, open Pycharm. You must agree to the Privacy Policy and click continue.
You can choose now whether you do or do not want to send Statistics.
You will be shown the customization page, you can choose the theme for PyCharm, or click on “Skip remaining and set Defaults”.
Run the Python script sample with Pycharm
Now click on the button
+ New Project:
Make sure all the options are selected like here below (beside username in the paths course), click
“create”
Wait for the program to finish “Creating Virtual Environment”
In the top toolbar go to file/settings/
Expand the menu Project:
pythonProject and click on Python Interpreter:
Click on the + sign on the right side of the page.
Add the following modules by searching them by name, selecting them one by one and clicking “install package” on the bottom
- Numpy
- Pillow
- opencv-python
Here you can see all packages installed as you should have:
When done close the interpreter packages window, click ok.
We can now run the Python sample
Within Pycharm > go to File, Open, and select C:\Program Files\Daheng Imaging\GalaxySDK\Samples\Python SDK\
GxSingleCamColor.py press OK.
Execute it Selecting in the Menu toolbar
Run and again
run. Choose GxSingleCamColor.py
(allow through firewall if asked)
*Please note that GXIPY folder should be on the location of the scripts
The sample will run. Besides performing the action in the sample (take picture, show it, etc.) it will also show the result of the operation within Pycharm. Return errors or warnings If any.
If you have followed these steps you are now able to aquere images by running python scripts in Pycharm.
If you have any questions about downloading, installing and running Python and PyCharm, make sure to
contact our Technical Support division or fill in the form below. They are always happy to help you out.