Skip to content

Commit c82b021

Browse files
authored
Merge pull request #5 from AdaptiveMotorControlLab/py36
Py36
2 parents dbf34d2 + 1c36c20 commit c82b021

File tree

10 files changed

+891
-83
lines changed

10 files changed

+891
-83
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
__pycache__/
2+
.ipynb_checkpoints/
3+
*test*
4+
*.pyc
5+
write_camera_details.py
6+
camera_details.json

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ This software package was written by [Gary Kane](https://github.com/gkane26), po
2222
1. Install the latest driver for your camera. You can find the driver from The Imaging Source website: https://www.theimagingsource.com/products/. **If you add new cameras to an existing system, make sure to update the driver!**
2323

2424
1. Clone this repository. Open command prompt (type "cmd" into the search bar and hit enter), then type:<br/><br/>
25-
``git clone https://github.com/AdaptiveMotorControlLab/camera_control``
25+
``git clone https://github.com/AdaptiveMotorControlLab/Camera_Control``
2626

2727
2. Open the camera control directory, **right-click 'install1.bat' and select 'Run as administrator'**<br/><br/>
28-
This script will install imaging source libraries, ffmpeg for command prompt, and create a new conda environment 'camera27'. Upon completion, the window will close suddenly.
28+
This script will install imaging source libraries, ffmpeg for command prompt, and create a new conda environment 'camera36'. Upon completion, the window will close suddenly.
2929

3030
3. Run 'install2.bat'.<br/><br/>
3131
This script will finish setting up the conda environment and create a desktop shortcut to open the GUI.
@@ -35,15 +35,15 @@ This script will finish setting up the conda environment and create a desktop sh
3535
- name = camera name
3636
- crop = cropping parameters
3737
- rotate = rotation angle of image
38-
- exposure = integer exposure values; can edit this in the GUI
38+
- exposure = exposure in ms; can edit this in the GUI
3939
- output_dir = default directory to save videos; can edit this in the GUI
4040
- Example:
4141

4242

4343
cam_0 = {'name' : 'Cog Rig',
4444
'crop' : {'top' : 150, 'left' : 225, 'height' : 250, 'width' : 300},
4545
'rotate' : 0,
46-
'exposure' : -14,
46+
'exposure' : .003,
4747
'output_dir' : 'C:/Users/user1/Desktop/video'}
4848

4949

camera_control_GUI.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
GUI to record from imaging source cameras during experiments
99
"""
1010

11-
from Tkinter import Entry, Label, Button, StringVar, IntVar, Tk, END, Radiobutton
12-
import tkFileDialog
13-
import ttk
11+
from tkinter import Entry, Label, Button, StringVar, IntVar, Tk, END, Radiobutton, filedialog, ttk
1412
import numpy as np
1513
import datetime
1614
import os
@@ -21,7 +19,6 @@
2119
import threading
2220
import json
2321
import nidaqmx
24-
import write_camera_details
2522

2623
class CamGUI(object):
2724

@@ -43,8 +40,9 @@ def __init__(self):
4340
self.selectCams()
4441

4542
def browse_output(self):
46-
filepath = tkFileDialog.askdirectory()
47-
self.output.set(filepath)
43+
if len(self.vid_out) == 0:
44+
filepath = filedialog.askdirectory()
45+
self.output.set(filepath)
4846

4947
def init_cam(self, num):
5048
# create pop up window during setup
@@ -92,7 +90,7 @@ def set_exposure(self, num):
9290
cam_check_window.mainloop()
9391
cam_check_window.destroy()
9492
else:
95-
self.cam[num].set_exposure(int(self.exposure[num].get()))
93+
self.cam[num].set_exposure(float(self.exposure[num].get()))
9694

9795
def lv_interrupt(self, task_handle, signal_type, callback_data):
9896

@@ -247,6 +245,7 @@ def start_record(self):
247245
self.vid_start_time = time.time()
248246
t = []
249247
for i in range(len(self.cam)):
248+
self.cam[i].set_frame_rate(int(self.fps.get()))
250249
t.append(threading.Thread(target=self.record_on_thread, args=(i,)))
251250
t[-1].daemon = True
252251
t[-1].start()
@@ -320,6 +319,9 @@ def save_vid(self, compress=False, delete=False):
320319

321320
def close_window(self):
322321

322+
if self.record_on.get():
323+
return
324+
323325
self.end_labview()
324326
if not self.setup:
325327
self.done = True

camera_env.yaml

Lines changed: 0 additions & 19 deletions
This file was deleted.

camera_env.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: camera36
2+
channels:
3+
- defaults
4+
dependencies:
5+
- certifi=2019.9.11=py36_0
6+
- pip=19.2.3=py36_0
7+
- python=3.6.9=h5500b2f_0
8+
- setuptools=41.2.0=py36_0
9+
- sqlite=3.29.0=he774522_0
10+
- vc=14.1=h0510ff6_4
11+
- vs2015_runtime=14.16.27012=hf0eaf9b_0
12+
- wheel=0.33.6=py36_0
13+
- wincertstore=0.2=py36h7fe50ca_0
14+
- pip:
15+
- ffmpy==0.2.2
16+
- imutils==0.5.3
17+
- nidaqmx==0.5.7
18+
- numpy==1.16.0
19+
- opencv-python==4.1.1.26
20+
- six==1.12.0

ic_camera.py

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88
camera class for imaging source cameras - helps load correct settings
99
"""
1010

11-
from pyicic.IC_ImagingControl import *
11+
import tisgrabber as ic
1212
import numpy as np
1313
import os
1414
import json
1515
import cv2
16+
import ctypes as C
1617

1718
path = os.path.dirname(os.path.realpath(__file__))
1819
dets_file = os.path.normpath(path + '/camera_details.json')
19-
with open(dets_file) as f:
20-
cam_details = json.load(f)
20+
cam_details = json.load(open(dets_file, 'r'))
2121

2222
class ICCam(object):
2323

24-
def __init__(self, cam_num=0, rotate=None, crop=None, exposure=None, format='Y800 (720x540)'):
24+
def __init__(self, cam_num=0, rotate=None, crop=None, exposure=None):
2525
'''
2626
Params
2727
------
@@ -31,65 +31,56 @@ def __init__(self, cam_num=0, rotate=None, crop=None, exposure=None, format='Y80
3131
default = None, uses default parameters specific to camera
3232
'''
3333

34-
self.ic_ic = IC_ImagingControl()
35-
self.ic_ic.init_library()
36-
3734
self.cam_num = cam_num
3835
self.rotate = rotate if rotate is not None else cam_details[str(self.cam_num)]['rotate']
3936
self.crop = crop if crop is not None else cam_details[str(self.cam_num)]['crop']
4037
self.exposure = exposure if exposure is not None else cam_details[str(self.cam_num)]['exposure']
4138

42-
self.cam = self.ic_ic.get_device(self.ic_ic.get_unique_device_names()[self.cam_num])
43-
self.cam.open()
44-
self.cam.set_video_format(format)
39+
self.cam = ic.TIS_CAM()
40+
self.cam.open(self.cam.GetDevices()[cam_num].decode())
4541
self.add_filters()
4642

4743
def add_filters(self):
4844
if self.rotate != 0:
49-
h_r = self.cam.create_frame_filter('Rotate Flip')
50-
self.cam.add_frame_filter_to_device(h_r)
51-
self.cam.frame_filter_set_parameter(h_r, 'Rotation Angle', self.rotate)
52-
53-
h_c = self.cam.create_frame_filter('ROI')
54-
self.cam.add_frame_filter_to_device(h_c)
55-
self.cam.frame_filter_set_parameter(h_c, 'Top', self.crop['top'])
56-
self.cam.frame_filter_set_parameter(h_c, 'Left', self.crop['left'])
57-
self.cam.frame_filter_set_parameter(h_c, 'Height', self.crop['height'])
58-
self.cam.frame_filter_set_parameter(h_c, 'Width', self.crop['width'])
45+
h_r = self.cam.CreateFrameFilter(b'Rotate Flip')
46+
self.cam.AddFrameFilter(h_r)
47+
self.cam.FilterSetParameter(h_r, b'Rotation Angle', self.rotate)
48+
49+
h_c = self.cam.CreateFrameFilter(b'ROI')
50+
self.cam.AddFrameFilter(h_c)
51+
self.cam.FilterSetParameter(h_c, b'Top', self.crop['top'])
52+
self.cam.FilterSetParameter(h_c, b'Left', self.crop['left'])
53+
self.cam.FilterSetParameter(h_c, b'Height', self.crop['height'])
54+
self.cam.FilterSetParameter(h_c, b'Width', self.crop['width'])
5955
self.size = (self.crop['width'], self.crop['height'])
6056

61-
self.cam.gain.auto = False
62-
self.cam.exposure.auto = False
63-
self.cam.exposure.value = self.exposure
64-
57+
def set_frame_rate(self, fps):
58+
self.cam.SetFrameRate(fps)
6559

6660
def set_exposure(self, val):
67-
try:
68-
val = int(round(val))
69-
val = val if val < self.cam.exposure.max-1 else self.cam.exposure.max-1
70-
val = val if val > self.cam.exposure.min else self.cam.exposure.min
71-
self.cam.exposure.value = val
72-
except:
73-
pass
61+
val = 1 if val > 1 else val
62+
val = 0 if val < 0 else val
63+
self.cam.SetPropertyAbsoluteValue("Exposure", "Value", val)
7464

7565
def get_exposure(self):
76-
return self.cam.exposure.value
66+
exposure = [0]
67+
self.cam.GetPropertyAbsoluteValue("Exposure", "Value", exposure)
68+
return round(exposure[0], 3)
7769

7870
def get_image(self):
79-
data, width, height, depth = self.cam.get_image_data()
80-
frame = np.ndarray(buffer=data,
81-
dtype=np.uint8,
82-
shape=(height, width, depth))
71+
self.cam.SnapImage()
72+
frame = self.cam.GetImageEx()
8373
return cv2.flip(frame,0)
8474

8575
def get_image_dimensions(self):
86-
_, width, height, _ = self.cam.get_image_data()
76+
im = self.get_image()
77+
height = im.shape[0]
78+
width = im.shape[1]
8779
return (width, height)
8880

89-
def start(self, show_display=True):
90-
self.cam.enable_continuous_mode(True)
91-
self.cam.start_live(show_display=show_display)
81+
def start(self, show_display=1):
82+
self.cam.SetContinuousMode(0)
83+
self.cam.StartLive(show_display)
9284

9385
def close(self):
94-
self.cam.stop_live()
95-
self.cam.close()
86+
self.cam.StopLive()

install1.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ powershell [System.Environment]::SetEnvironmentVariable('PATH', '%NEW_PATH%', 'M
3131

3232
echo.
3333
echo.
34-
echo Create New Conda Environment: camera27
34+
echo Create New Conda Environment: camera36
3535
call activate.bat
36-
conda env create -f camera_env.yaml
36+
conda env create -f camera_env.yml

install2.bat

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
echo OFF
22

3-
@setlocal enableextensions
4-
@cd /d "%~dp0"
5-
63
echo.
74
echo.
8-
echo Install Imaging Source Python Package
9-
call activate camera27
10-
pip install git+https://github.com/morefigs/py-ic-imaging-control
5+
echo Initialize system setup via write_camera_details.py file
116
copy write_camera_details_TEMPLATE.py write_camera_details.py
127
python write_camera_details.py
138

@@ -16,7 +11,7 @@ echo.
1611
echo.
1712
echo Write Shortcut File to the Desktop
1813
echo call activate.bat > C:%HOMEPATH%\Desktop\cameraGUI.bat
19-
echo call activate camera27 >> C:%HOMEPATH%\Desktop\cameraGUI.bat
14+
echo call activate camera36 >> C:%HOMEPATH%\Desktop\cameraGUI.bat
2015
echo cd %cd% >> C:%HOMEPATH%\Desktop\cameraGUI.bat
2116
echo python camera_control_GUI.py >> C:%HOMEPATH%\Desktop\cameraGUI.bat
2217

0 commit comments

Comments
 (0)