Machine Vision Assistant
MV Course Code Generation
When generating code for MV (Machine Vision) course labs, use bilingual comment style (Chinese + English, 中文在上英文在下).
Comment Style Requirements
Bilingual Format (Chinese first, English second):
# 要求:[作业要求中文] # [技术解释中文] # Requirement: [Assignment requirement in English] # [Technical explanation in English]
Key Principles:
- •Start with
# 要求:to mark assignment requirements (Chinese first) - •Explain WHY technical choices are made
- •Provide parameter explanations
- •Mention alternative approaches when relevant
- •Chinese first, then English translation (中文在上,英文在下)
- •Keep comments concise but informative
Example:
# 要求:将图像从 RGB 转换为灰度图 # 从文件加载图像 # Requirement: Convert image from RGB to Grayscale # Load image from file img = cv2.imread(image_path) gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 要求:应用高斯模糊 # 边缘检测前降噪以防止图像噪声导致的误判边缘点 # 注意:高斯模糊使用加权平均,适合一般降噪 # 替代方案:中值模糊(cv2.medianBlur)使用中值,更适合椒盐噪声 # Requirement: Apply Gaussian blur # Reduce noise before edge detection to prevent false edge points caused by image noise # Note: Gaussian blur uses weighted average, good for general noise reduction # Alternative: Median blur (cv2.medianBlur) uses median value, better for salt-and-pepper noise blurred_image = cv2.GaussianBlur(img, (blur_ksize, blur_ksize), 0)
Docstring Format:
def function_name(param):
"""
中文函数说明。
English function description.
中文详细解释:
English detailed explanation:
-------------------------------------------------------------------------
中文内容
English content
-------------------------------------------------------------------------
Args:
param: 中文参数说明 / English parameter description
Returns:
中文返回值说明
English return description
"""
For complete example: See Lab3 code at courses/mv/labs/lab3_orb.ipynb
Python File Format for Jupyter Conversion
When creating .py files that will be converted to Jupyter notebooks, use jupytext-compatible format:
File Structure:
# ---
# jupyter:
# jupytext:
# text_representation:
# extension: .py
# format_name: light
# ---
# # Lab Title - Main Heading
#
# **Objective:**
# Description of lab objectives
#
# **Materials Required:**
# - Item 1
# - Item 2
#
# **Lab Duration:** X hours
import cv2
import numpy as np
from matplotlib import pyplot as plt
# ## Part 1: Section Title
#
# Brief description of this part
#
# **Exercise 1:** Exercise description
def function_name(params):
# Requirement: What this code does
# Technical explanation
# 要求:这段代码做什么
# 技术解释
code_here
# ## Test Exercise 1: Title
#
# Description of what this test does
# +
# 测试练习 1
# Test code for Exercise 1
print('Exercise 1: ...')
result = function_name(params)
# -
Key Rules:
- •Use
#prefix for Markdown content (becomes Markdown cells) - •Use
# #for main headings,# ##for subheadings - •Use
#with blank line for paragraph breaks - •Regular
#comments inside functions (stays as code comments) - •File header with jupytext metadata ensures proper conversion
- •Use
# +and# -to mark cell boundaries for test code blocks
Cell Separation:
- •Each function definition: separate code cell
- •Each test/exercise execution: separate code cell with Markdown header
- •Use
# +at start and# -at end to explicitly mark cell boundaries - •Markdown sections (
# ## ...) automatically create new cells
Conversion Command:
uv run jupytext --to notebook file.py -o file.ipynb
Why This Format:
- •✅ File header becomes Markdown cell (not code)
- •✅ Section titles become Markdown cells
- •✅ Exercise descriptions become Markdown cells
- •✅ Function code becomes code cells
- •✅ Bilingual comments preserved in code cells
Image Display Rule:
- •Always use
plt.show()in test cells to display results directly in the Notebook. - •Avoid using
plt.close()in Notebook-targeted code as it prevents visual output. - •Optional: Keep
plt.savefig()if a permanent record is needed, butplt.show()must follow it or be used standalone.
For complete example: See courses/mv/labs/CST8508_Lab2.py
Core Workflows
Understanding Concepts
Ask for explanations at your level (beginner/intermediate/advanced). Request real-world industrial examples for intuition, then mathematical formulations when ready.
For detailed concept explanations: See references/concepts.md
Analyzing Code
Share OpenCV/Python code snippets and specify what you want to understand (algorithm flow, parameter tuning, optimization). Ask about common implementation pitfalls.
For implementation patterns and examples: See references/implementation.md
Completing Homework
Describe the vision problem and what you've tried. Ask for hints on algorithm selection and debugging strategies, not solutions. Verify your approach before implementing.
Running Experiments
- •Define vision task goal
- •Set up baseline algorithm
- •Change one parameter at a time
- •Analyze results with metrics and visualizations
For experiment templates: See references/experiments.md
Testing Knowledge
Specify topics (filtering, edge detection, segmentation, etc.), question types (conceptual/mathematical/coding/applied), and difficulty level.
Reviewing Material
Request summaries, algorithm comparison tables, parameter cheat sheets, or processing pipeline diagrams.
For quick reference: See references/quick-ref.md
Planning Projects
Follow phases: Requirements → Algorithm Selection → Implementation → Testing → Optimization
For project ideas and structure: See references/projects.md
Reading Papers
Use three-pass approach: (1) Abstract/figures/conclusion, (2) Problem/method/experiments, (3) Mathematical details/implementation
For key papers: See references/papers.md
Common Pitfalls
- •Poor lighting conditions not considered
- •Incorrect image preprocessing order
- •Wrong kernel size for filtering
- •Not handling edge cases in segmentation
- •Ignoring real-time performance constraints
- •Inadequate camera calibration
Best Practices
- •Start with simple algorithms before complex ones
- •Visualize intermediate processing steps
- •Test with diverse image conditions
- •Use established libraries (OpenCV, scikit-image)
- •Benchmark against baseline methods
- •Consider lighting and hardware constraints