def lane_detect(img):
    frameWidth = w
    frameHeight = h
    intialTracbarVals = (38, 60, 12, 90)
    count = 0
    noOfArrayValues = 11
    global arrayCurve, arrayCounter
    arrayCounter = 0
    arrayCurve = np.zeros([noOfArrayValues])
    myVals = []
    #utlis.initializeTrackbars(intialTracbarVals)

    # imgWarpPoints = img.copy()
    imgFinal = img.copy()
    imgCanny = img.copy()
    try:

        # imgUndis = utlis.undistort(img)
        imgThres, imgCanny, imgColor = utlis.thresholding(img)
        src = utlis.valTrackbars()
        imgWarp = utlis.perspective_warp(imgThres,
                                         dst_size=(frameWidth, frameHeight),
                                         src=src)
        # imgWarpPoints = utlis.drawPoints(imgWarpPoints, src)
        imgSliding, curves, lanes, ploty = utlis.sliding_window(
            imgWarp, draw_windows=False)

        curverad = utlis.get_curve(imgFinal, curves[0], curves[1])
        lane_curve = np.mean([curverad[0], curverad[1]])
        imgFinal = utlis.draw_lanes(img,
                                    curves[0],
                                    curves[1],
                                    frameWidth,
                                    frameHeight,
                                    src=src)
        #currentCurve = lane_curve // 50
        # if  int(np.sum(arrayCurve)) == 0:averageCurve = currentCurve
        # else:
        #     averageCurve = np.sum(arrayCurve) // arrayCurve.shape[0]
        # if abs(averageCurve-currentCurve) >200: arrayCurve[arrayCounter] = averageCurve
        # else :arrayCurve[arrayCounter] = currentCurve
        # arrayCounter +=1
        # if arrayCounter >=noOfArrayValues : arrayCounter=0
        # cv2.putText(imgFinal, str(int(averageCurve)), (frameWidth//2-70, 70), cv2.FONT_HERSHEY_DUPLEX, 1.75, (0, 0, 255), 2, cv2.LINE_AA)
        # imgFinal= utlis.drawLines(imgFinal,lane_curve)
    except:
        # print("NO Lane Detected")
        imgFinal = img
        cv2.putText(imgFinal, "No Lane Detected", (10, 20),
                    cv2.FONT_HERSHEY_DUPLEX, 1, (0, 0, 255), 1, cv2.LINE_AA)

    return imgFinal
    success, img = cap.read()
    #img = cv2.imread('test3.jpg')
    if cameraFeed== False:img = cv2.resize(img, (frameWidth, frameHeight), None)
    imgWarpPoints = img.copy()
    imgFinal = img.copy()
    imgCanny = img.copy()

    imgUndis = utlis.undistort(img)
    imgThres,imgCanny,imgColor = utlis.thresholding(imgUndis)
    src = utlis.valTrackbars()
    imgWarp = utlis.perspective_warp(imgThres, dst_size=(frameWidth, frameHeight), src=src)
    imgWarpPoints = utlis.drawPoints(imgWarpPoints, src)
    imgSliding, curves, lanes, ploty = utlis.sliding_window(imgWarp, draw_windows=True)

    try:
        curverad =utlis.get_curve(imgFinal, curves[0], curves[1])
        lane_curve = np.mean([curverad[0], curverad[1]])
        imgFinal = utlis.draw_lanes(img, curves[0], curves[1],frameWidth,frameHeight,src=src)

        # ## Average
        currentCurve = lane_curve // 50
        if  int(np.sum(arrayCurve)) == 0:averageCurve = currentCurve
        else:
            averageCurve = np.sum(arrayCurve) // arrayCurve.shape[0]
        if abs(averageCurve-currentCurve) >200: arrayCurve[arrayCounter] = averageCurve
        else :arrayCurve[arrayCounter] = currentCurve
        arrayCounter +=1
        if arrayCounter >=noOfArrayValues : arrayCounter=0
        cv2.putText(imgFinal, str(int(averageCurve)), (frameWidth//2-70, 70), cv2.FONT_HERSHEY_DUPLEX, 1.75, (0, 0, 255), 2, cv2.LINE_AA)

    except: