Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
ef454c8
Add Python folder of Camera Examples
rollypop Sep 2, 2025
0b582f7
first commit
rollypop Sep 2, 2025
f4964a7
change exposure time
rollypop Sep 4, 2025
9df6e83
코드 대폭 개선 및 md도 수정
rollypop Sep 4, 2025
ee4d6ab
워밍업 로그도 뜨게 만듬. 그리고 로그 안뜰때 경고도 나오게
rollypop Sep 4, 2025
ee988dc
trigger polarity 설정
rollypop Sep 4, 2025
9025423
다 돌아가고 마지막부분에 뜬 메세지
rollypop Sep 4, 2025
17e44d2
실시간 그래프 플롯 부분 수정
rollypop Sep 4, 2025
7da84e4
주석변경
rollypop Sep 5, 2025
656a673
camera arm 이후 0.5ms 안정화 시간 추가 확보
rollypop Sep 11, 2025
506cb06
안정화 1.5s로 늘림
rollypop Sep 11, 2025
972d7a2
window setup그거긴 한데 일단 커밋하고 지우든가 하자. gitignore에 추가할 예정
rollypop Sep 11, 2025
54c5e74
.gitignore 수정 .h5랑 파이썬 캐시는 무시하도록
rollypop Sep 11, 2025
daacdad
엣지 극성 바꿔봄
rollypop Sep 11, 2025
1099427
two channel 전략 반영
rollypop Sep 11, 2025
23d737e
아,,, gitignore 풀 해야했다
rollypop Sep 11, 2025
58be58f
맥에서도 시스템 파일 무시하도록 해놓음
rollypop Sep 11, 2025
eda2fa4
카메라 트리거링 다시 low to high로 바꿈
rollypop Sep 11, 2025
464b311
카메라가 타임스탬프 지원하는지 확인하는 절차 추가
rollypop Sep 11, 2025
0f7185c
트리거 주파수 변경 및 roi 비닝 추가
rollypop Sep 11, 2025
e67c616
이거 왜,,,
rollypop Sep 11, 2025
bdfc47b
hd5 resizing 문제 수정
rollypop Sep 11, 2025
f0f59b8
live plot 멈춤 문제 수정
rollypop Sep 11, 2025
1d914a2
roi 안잡혀서 데이터 저장 안되는 문제 수정
rollypop Sep 11, 2025
7c550ba
ROI 비닝 파트 재구성
rollypop Sep 11, 2025
965da69
aerodiode 메뉴얼 및 라이브러리
rollypop Sep 11, 2025
6d3d04c
ODMR 상위 구간 기준 더 타이트하게 잡도록 수정
rollypop Sep 12, 2025
2857e96
live plot 표기법 바꿈 논문 그림처럼 나오게
rollypop Sep 12, 2025
29acf80
ROI 영역이 부담이 되는건가,,,, 일단 다시 ROI 쪽 수정해봄
rollypop Sep 12, 2025
f324094
비상정지 시스템 가동부분 추가
rollypop Sep 12, 2025
5968f96
옛날버전 테스트할때 깃 안꼬이도록 gitignore 수정
rollypop Sep 12, 2025
b83bd8f
name error 수정
rollypop Sep 12, 2025
e9b2574
WAIT 이슈 처리위한 추가한 나머지것들 제거 단 워치독은 유지
rollypop Sep 12, 2025
08acff6
producer part 비닝 이슈 수정
rollypop Sep 12, 2025
50416fd
예전 ODMR 상위 구간 기준 더 타이트하게 잡을 때로 producer 원상복구,,,
rollypop Sep 12, 2025
7d4f1ed
예전 기준 타이트하게 잡기로 다시 되돌아가기 2...
rollypop Sep 12, 2025
743a95c
진짜로 원상복구해서 거기다가 워치독이랑 요약로그 파일 리네임만 넣음
rollypop Sep 12, 2025
0f1fa70
live plot 축 변경
rollypop Sep 12, 2025
f709bc2
.txt도 ignore에 포함시키자
rollypop Sep 12, 2025
f381184
.txt도 ignore에 추가
rollypop Sep 12, 2025
dc89fee
CW ODMR 그래프 만드는 노트북 생성
rollypop Sep 12, 2025
b3bda0a
그래프 만드는 노트북 수정
rollypop Sep 12, 2025
4c74709
주파수 폴더 생성 뺴기
rollypop Sep 12, 2025
675ae07
sdg 파라미터 확인
rollypop Sep 12, 2025
9f2d465
ch2 위상 뒤집기 시도
rollypop Sep 12, 2025
1c6fbc3
ch2 위상 뒤집기 시도...2
rollypop Sep 12, 2025
00cde36
MW on/off 페어링을 위해 freq list sweep으로 변경 및 그에 따른 freq-frame 매핑 방법 변경
rollypop Sep 15, 2025
4e7d6e9
experiment mardown 파일 수정
rollypop Sep 18, 2025
45f4221
ROI 메뉴얼 설정으로 변경 및 주파수 25Hz로 다 변경. 노출시간 20ms. 만약 해봤는데 안먹히면 되돌아오기
rollypop Sep 19, 2025
f6ee660
이전꺼 되긴 하는데 또 ROI는 작게 잡히고 있어서 다시 시도
rollypop Sep 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
19 changes: 18 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,21 @@
*.exe
*.ilk
*.obj
*.cfg
*.cfg

# 실험 데이터
*.h5
*.hdf5

# 파이썬 캐시 파일
*.pyc
__pycache__/

# macOS 시스템 파일
*.DS_Store

# 옛날 파일
*_old.py

# txt 파일
*.txt
Binary file added Python/.DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions Python/20250912_030534/run_summary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ended_at: 2025-09-12T03:24:25.187737
result: OK
frames_captured: 20000
frames_processed: 19954
unique_freqs: 20
hdf5: data.h5
153 changes: 153 additions & 0 deletions Python/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

This is the Python implementation of Thorlabs Scientific Camera examples. The code demonstrates camera control functionality including software triggering, continuous frame capture, and MP4 video recording using the Thorlabs TSI SDK.

## Development Guidelines

**IMPORTANT**: When making any code changes or additions:
- Base all coding decisions on the Thorlabs official examples in this directory
- Refer to the official Thorlabs Camera Python API Reference at `/Users/woojins/Documents/GitHub/Camera_Examples/Python/Thorlabs_Camera_Python_API_Reference.pdf`
- Follow the patterns and conventions established in the existing official examples
- Use only the APIs and methods documented in the official reference

## CW ODMR Experiment Setup

**CRITICAL**: For the CW ODMR experiment:
- **SynthHD Configuration**: The Windfreak SynthHD is pre-configured to "single step per trigger" mode
- **No SynthHD Control Needed in Code**: When SDG2082x CH.1 sends a trigger pulse, the SynthHD automatically advances to the next frequency step (50MHz increment)
- **Synchronization**: Each SDG trigger simultaneously:
1. Triggers camera to capture one frame (20ms exposure)
2. Triggers SynthHD to advance to next frequency step
- **Frame-Frequency Matching**: Frame N corresponds to frequency = 3.000 + ((N-1) % 20) × 0.050 GHz
- **No Manual SynthHD Programming Required**: The hardware is pre-configured externally

## Architecture

The Python examples use the Thorlabs TSI SDK with OpenCV for image processing and display:
- **thorlabs_tsi_sdk.tl_camera**: Core camera control and frame acquisition
- **thorlabs_tsi_sdk.tl_mono_to_color_processor**: Color processing for Bayer sensor cameras
- **opencv-python**: Image display and MP4 video writing
- **numpy**: Array manipulation for image data

All examples depend on the Thorlabs TSI Camera SDK Python package and native DLLs.

## Setup and Installation

### Required Dependencies
```bash
# Install Thorlabs Python SDK (from ThorCam installation)
python -m pip install thorlabs_tsi_camera_python_sdk_package.zip

# Install additional Python packages
pip install opencv-python numpy

# If requirements.txt exists in ThorCam SDK examples
pip install -r requirements.txt
```

### DLL Setup (Windows)
1. Copy Native DLLs from ThorCam installation:
- Source: `\Scientific Camera Interfaces\SDK\Native Toolkit\dlls\Native_64_lib`
- Destination: `./dlls/64_lib/` (relative to Python scripts)
2. The `windows_setup.py` script handles DLL path configuration automatically

### Running Examples
```bash
# Single frame capture with display
python grab_single_frame.py

# Continuous frame capture (Ctrl+C to stop)
python grab_frames_polling_continuous.py

# Record MP4 video (200 frames)
python opencv_mp4_writer_example.py
```

## SDK Dependencies

### Thorlabs Scientific Camera SDK
- **Installation**: Download and install ThorCam software package from Thorlabs
- **Location**: `Program Files\Thorlabs\Scientific Imaging\Scientific Camera Support\`
- **Archive**: Extract `Scientific Camera Interfaces.zip`
- **Python Package**: `SDK\Python Toolkit\thorlabs_tsi_camera_python_sdk_package.zip`
- **Native DLLs**: `SDK\Native Toolkit\dlls\Native_64_lib\` → copy to `./dlls/64_lib/`

### Python Dependencies
- **thorlabs_tsi_sdk**: Main camera control SDK
- **opencv-python**: Image processing and video writing
- **numpy**: Array operations for image data

## Available Examples

### grab_single_frame.py
- Initializes first detected camera
- Sets 10ms exposure time and continuous mode
- Captures single frame with software trigger
- Displays image using OpenCV (grayscale converted to RGB)
- Key pattern: SDK context manager, software triggering, OpenCV display

### grab_frames_polling_continuous.py
- Continuous frame capture with 10 FPS frame rate control
- Polls for frames in infinite loop (Ctrl+C to exit)
- Real-time OpenCV display with frame counting
- Key pattern: Continuous acquisition, polling, frame rate control

### opencv_mp4_writer_example.py
- Records 200 frames to `video.mp4` file
- Supports both monochrome and color (Bayer) cameras
- Automatic color processing for Bayer sensors (BGR format)
- Scales bit depth to 8-bit for MP4 compatibility
- Key pattern: Video recording, color processing, proper resource cleanup

## Key Programming Patterns

### SDK Context Management
```python
with TLCameraSDK() as sdk:
with sdk.open_camera(camera_id) as camera:
# Camera operations here
pass
# Automatic cleanup handled by context managers
```

### Frame Acquisition
```python
camera.arm(2) # Arm camera with 2-frame buffer
camera.issue_software_trigger()
frame = camera.get_pending_frame_or_null()
if frame is not None:
image_data = np.copy(frame.image_buffer)
```

### Image Data Handling
- Raw data comes as 1D array, reshape using camera dimensions
- Convert to OpenCV format (BGR for color, grayscale to RGB for display)
- Handle bit depth scaling for 8-bit outputs

### Windows DLL Loading
- Import and call `windows_setup.configure_path()` before SDK imports
- Handles both 32-bit and 64-bit DLL detection
- Gracefully handles non-Windows platforms

## Common Camera Parameters

- `camera.exposure_time_us`: Exposure time in microseconds
- `camera.frames_per_trigger_zero_for_unlimited`: 0 for continuous mode
- `camera.image_poll_timeout_ms`: Frame polling timeout
- `camera.frame_rate_control_value`: Target frame rate
- `camera.is_frame_rate_control_enabled`: Enable/disable frame rate limiting
- `camera.image_width_pixels`, `camera.image_height_pixels`: Image dimensions
- `camera.bit_depth`: Sensor bit depth
- `camera.camera_sensor_type`: SENSOR_TYPE.BAYER for color cameras

## Testing

Testing requires physical Thorlabs camera hardware:
1. Connect camera via USB
2. Ensure ThorCam software can detect the camera
3. Run Python examples to verify SDK integration
4. Check OpenCV display windows and generated MP4 files
Loading