采集卡bug修复

This commit is contained in:
Ray
2025-10-29 15:37:48 +08:00
parent 3a8873acc2
commit f0fc28d827
3 changed files with 33 additions and 6 deletions

View File

@@ -202,11 +202,22 @@ class ConfigGUI:
import warnings import warnings
found = [] found = []
# 临时设置OpenCV日志级别 # 临时设置OpenCV日志级别(兼容不同版本)
import os import os
old_level = os.environ.get('OPENCV_LOG_LEVEL', '') old_level = os.environ.get('OPENCV_LOG_LEVEL', '')
os.environ['OPENCV_LOG_LEVEL'] = 'ERROR' os.environ['OPENCV_LOG_LEVEL'] = 'ERROR'
# 尝试设置日志级别不同版本的OpenCV API不同
try:
if hasattr(cv2, 'setLogLevel'):
# OpenCV 4.x
if hasattr(cv2, 'LOG_LEVEL_ERROR'):
cv2.setLogLevel(cv2.LOG_LEVEL_ERROR) cv2.setLogLevel(cv2.LOG_LEVEL_ERROR)
elif hasattr(cv2, 'utils'):
# 某些版本的OpenCV
cv2.utils.setLogLevel(0) # 0=ERROR级别
except Exception:
pass # 如果设置失败,继续执行
try: try:
for idx in range(max_index + 1): for idx in range(max_index + 1):

View File

@@ -8,9 +8,17 @@ import warnings
import os import os
from config import config_manager from config import config_manager
# 抑制OpenCV的警告信息 # 抑制OpenCV的警告信息(兼容不同版本)
os.environ['OPENCV_LOG_LEVEL'] = 'ERROR' os.environ['OPENCV_LOG_LEVEL'] = 'ERROR'
cv2.setLogLevel(cv2.LOG_LEVEL_ERROR) try:
if hasattr(cv2, 'setLogLevel'):
# OpenCV 4.x
if hasattr(cv2, 'LOG_LEVEL_ERROR'):
cv2.setLogLevel(cv2.LOG_LEVEL_ERROR)
elif hasattr(cv2, 'utils'):
cv2.utils.setLogLevel(0) # 0=ERROR级别
except Exception:
pass # 如果设置失败,继续执行
class PreviewWindow: class PreviewWindow:
"""采集卡预览窗口""" """采集卡预览窗口"""

View File

@@ -43,10 +43,18 @@ import cv2
import threading import threading
import warnings import warnings
# 抑制OpenCV的警告信息 # 抑制OpenCV的警告信息(兼容不同版本)
import os import os
os.environ['OPENCV_LOG_LEVEL'] = 'ERROR' os.environ['OPENCV_LOG_LEVEL'] = 'ERROR'
cv2.setLogLevel(cv2.LOG_LEVEL_ERROR) try:
if hasattr(cv2, 'setLogLevel'):
# OpenCV 4.x
if hasattr(cv2, 'LOG_LEVEL_ERROR'):
cv2.setLogLevel(cv2.LOG_LEVEL_ERROR)
elif hasattr(cv2, 'utils'):
cv2.utils.setLogLevel(0) # 0=ERROR级别
except Exception:
pass # 如果设置失败,继续执行
class GetImage: class GetImage:
def __init__(self, cam_index=0, width=1920, height=1080): def __init__(self, cam_index=0, width=1920, height=1080):