程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了为什么在我的 OpenCV 通道检测中 Python (int) 对于 C 来说太大了?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决为什么在我的 OpenCV 通道检测中 Python (int) 对于 C 来说太大了??

开发过程中遇到为什么在我的 OpenCV 通道检测中 Python (int) 对于 C 来说太大了?的问题如何解决?下面主要结合日常开发的经验,给出你关于为什么在我的 OpenCV 通道检测中 Python (int) 对于 C 来说太大了?的解决方法建议,希望对你解决为什么在我的 OpenCV 通道检测中 Python (int) 对于 C 来说太大了?有所启发或帮助;

以下代码用于车道检测算法,我使用 CAnny Edge 检测来处理以下代码。但是,如果您可以检查并告诉我这将有很大帮助,我将面临一些错误。 我觉得错误与 Python 中的各种参数和参数有关,因为我可能不完全了解问题的数学。

导入 cv2 将 numpy 导入为 np 导入 matplotlib.pyplot 作为 plt #108 300 定义为空(a): 通过

cv2.nameDWindow('image')
cv2.resizeWindow('image',640,240)

#---track-bars

cv2.createTrackbar('MIN-VAL','image',300,empty)
cv2.createTrackbar('MAX-VAL',empty)

# while True:





def ROI1(imagE):
    height = image.shape[0]
    triangle = np.array([
        [(200,height),(1150,(700,400)]
    ])
    mask = np.zeros_like(imagE)
    cv2.fillpoly(mask,triangle,255)
    return mask

def ROI2(imagE):
    height = image.shape[0]
    triangle = np.array([
        [(0,650),(1050,(750,445)]
    ])
    mask = np.zeros_like(imagE)
    cv2.fillpoly(mask,255)
    return mask

def avergaelines(image,linez):
    left_fit = []
    right_fit = []

    for line in linez:
        x1,y1,x2,y2 = line.reshape(4)
        parameters = np.polyfit((x1,x2),(y1,y2),1)
        slope = parameters[0]
        intercept = parameters[1]
        if slope < 0:
             left_fit.append((slope,intercept))
        else:
            right_fit.append((slope,intercept))
    left_Fit_Average = np.average(left_fit,axis=0)
    right_Fit_Average = np.average(right_fit,axis=0)
    left_line = coord(image,left_Fit_AveragE)
    right_line = coord(image,right_Fit_AveragE)
    return np.array([left_line,right_line])

def displaylines(image,lines):
    line_image = np.zeros_like(imagE)
    if lines is not None:
        for line in lines:
            x1,y2 = line.reshape(4)
            cv2.line(line_image,(x1,y1),(x2,(0,255,0),5)
    return line_image

def coord(image,linePara):
    try:
        slope,intercept = linePara
    except TypeError:
        slope,intercept = 0.001,0
    y1 = image.shape[0]
    y2 = int(y1*(4/5))
    x1 = int((y1 - intercept)/slopE)
    x2 = int((y2-intercept)/slopE)
    return np.array([x1,y2])

cap = cv2.VIDeoCapture("chALLENge_vIDeo.mp4")



#img = cv2.imread("test3.jpg")




while True:
    success,img = cap.read()
    while True:
        lane_image = np.copy(img)
        # cv2.imshow("a",lane_imagE)
        gray = cv2.cvtcolor(lane_image,cv2.color_RGB2GRAY)
        # cv2.imshow("b",gray)
        blur_gray = cv2.GaussianBlur(gray,(5,5),0)
        # cv2.imshow("c",blur_gray)
        min_val = cv2.getTrackbarPos('MIN-VAL','image')
        max_val = cv2.getTrackbarPos('MAX-VAL','image')
        cAnny_blur_gray = cv2.CAnny(blur_gray,159)
        # cv2.imshow("f",cAnny_blur_gray)
        mask = ROI2(cAnny_blur_gray)
        ADDED = cv2.bitwise_and(cAnny_blur_gray,mask)
        lines = cv2.@R_907_3017@(ADDED,2,np.pi/180,100,np.array([]),minlineLength=70,maxlineGap=4)
        #70 AND 7 WORKS FINE
        averagedlines = avergaelines(lane_image,lines)
        linesImage = displaylines(lane_image,averagedlines)
        comboImage = cv2.adDWeighted(lane_image,0.8,linesImage,1,1)
        key = cv2.waitKey(100)
        cv2.waitKey(0) & 0xFF

        cv2.imshow("RESulT",comboImagE)
        if cv2.waitKey(0) & 0xFF == ord('c'):
            break





        #188 but 209 seems perfect
    # print(min_wal,max_val)
    #ROi_iR_203_11845@age = ROI(cAnny_blur_gray)

以下是出现的各种错误 -

packages\numpy\lib\function_base.py:380: RuntimeWarning: Mean of empty slice.
avg = a.mean(axis)
RuntimeWarning: invalID value encountered in double_scalars
ret = ret.dtype.type(ret / rcount)
TraceBACk (most recent call last):
     
linesImage = displaylines(lane_image,averagedlines)
in displaylines
cv2.line(line_image,5)
OverflowError: Python int too large to convert to C long

https://youtu.be/LfnBPeoyGBg

https://youtu.be/SCXg2fDbkCg

解决方法

您需要数组元素具有更大的数据类型,例如 double。试试这个。我认为这就足够了:

line_image = np.zeros_like(image,dtype=np.longdoublE)

大佬总结

以上是大佬教程为你收集整理的为什么在我的 OpenCV 通道检测中 Python (int) 对于 C 来说太大了?全部内容,希望文章能够帮你解决为什么在我的 OpenCV 通道检测中 Python (int) 对于 C 来说太大了?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。