第一次问,经过几天的寻找,我还没有找到任何答案。而且我绝对不是编程专家,所以我可能错过了一些显而易见的东西。
我正在运行一个遍历大型图像库(大约2M)并从中提取信息的代码。该代码可以很好地运行几次迭代(20-10000ish),但是程序会立即停止运行,而不会报告任何错误。
大多数时候,主代码在OpenCV边缘检测或信号线处退出(终止?),但并非总是如此。大约是代码中其他时间的10%。
使用:
OpenCV 4.1.1 的Python 3.7.1 Windows 10
图片位于:https://www.dropbox.com/s/5lfzkw6sqmu73eb/Image_00_00_00_00.bmp?dl=0
我试图以某种方式从Opencv代码中获取异常,但是没有弹出。最近的尝试在下面的代码中。
我尝试使用跟踪和日志模块,但是我无法真正使它们做任何有用的事情。
import numpy as np
import cv2
import traceback
import sys
def cropping_points2(img):
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) # Gray image needed for edge detection
try:
edges = cv2.Canny(gray,20,70,apertureSize = 3)
except Exception as e:
print(traceback.format_exc())
print(sys.exc_info())
print(e,'there was actually an exception!')
exit()
lines = []
try:
lines = cv2.HoughLines(edges,3,np.pi/180,65,50,10,min_theta = 1.4,max_theta = 1.75) # analyse image to find lines - thetha setting looks for horizontal
except Exception as e:
print(traceback.format_exc())
print(sys.exc_info())
print(e,'there was actually an exception!')
exit()
if lines is None: # All black images return a NoneType image
print('no lines!') # Capture NoneType without crashiing
rect = []
has_lines = False
return rect,has_lines
has_lines = True
return lines[0][0],has_lines
if __name__ == "__main__":
img= cv2.imread('Image_00_00_00_00.bmp')
for index in range(10000):
rect,has_lines = cropping_points2(img)
print(rect)
print(index)
我希望程序能提示我为什么停止运行= |