【问题标题】:what actually does ths error mean when i try to run my code i ran into the erro, the error in metioned beneath the code当我尝试运行我的代码时,这个错误实际上是什么意思我遇到了错误,代码下面提到的错误
【发布时间】:2022-05-24 17:23:41
【问题描述】:

这是我遇到问题的代码,我在名为 rohith 的库中编写了几个函数(代码末尾提供了链接,请随时下载)

        import cv2
        import rohith
        import numpy as np
        videoPath = 'project_video.mp4'
        cap = cv2.VideoCapture(videoPath)

        def lane_tracking(img, lines):
            copy_image= np.copy(img)
            merginig_img = np.zeros((img.shape[0],img.shape[1],3),
                                  dtype = np.uint8)
            for line in lines:
                for x1,y1,x2,y2 in line:
                    cv2.line(merginig_img,(x1,y1),(x2,y2),(10,255,255),
                             thickness=4)

            merged_img =cv2.addWeighted(copy_image,
                                        0.8,
                                        merginig_img,
                                        1,
                                        0.0)
          ''merging the lane detected image(which includes only roi) with original image(frame)''
            return  merged_img

        while(True):


             ret,frame = cap.read()

             processed_image = rohith.preprocess(frame)

             width = processed_image.shape[0]
             height = processed_image.shape[1]

             region_of_interest_vertices = [
                  (0, width), (height / 2, width / 2), (height, width)
             ]

             gray_scale = cv2.cvtColor(processed_image,cv2.COLOR_BGR2GRAY)
             edge_detection = cv2.Canny(gray_scale, 55, 150)               
             cropped_image=rohith.region_of_interest(edge_detection,
                                      np.array([region_of_interest_vertices],
                                      np.int32))



             lane_tracking1 = cv2.HoughLinesP(cropped_image,
                                             rho=6, theta=np.pi / 60,
                                             threshold=160,
                                             lines=np.array([]),
                                             minLineLength=40,
                                             maxLineGap=25)

             line_added_img = lane_tracking(processed_image,lane_tracking1)



             cv2.imshow('edge detected image with only lanes',cropped_image)
             cv2.imshow('video_with_lane_lines', line_added_img)



             if cv2.waitKey(1) & 0xFF == ord('p'):
                 break
        cap.release()
        cv2.destroyAllWindows()
  1. ///在我尝试运行时遇到代码错误之后,我正在使用 pycharm 在 python 中运行我的代码(链接到 rohith 库------->>>> https://drive.google.com/file/d/1TKXwGcBZXKS5Y3n9aXze5TVVjaOc9kB6/view?usp=sharing

            Traceback (most recent call last):
            File 
           "C:/Users/dell/PycharmProjects/lane_detection/test02.py",line28,
            in <module>
            processed_image = rohith.preprocess(frame)
            File "C:\Users\dell\PycharmProjects\lane_detection\rohith.py", 
            line 5, in
            preprocess
            filtering = cv2.GaussianBlur(frame, (5,5),0)
            cv2.error: OpenCV(4.1.2) C:\projects\opencv- 
            python\opencv\modules\core\src\matrix.cpp:757:
            error: (-215:Assertion failed) dims <= 2 && step[0] > 0 in 
            function
            'cv::Mat::locateROI'
            Process finished with exit code 1
    

【问题讨论】:

  • 请正确格式化。不格式化很难阅读。
  • 抱歉让您感到不适..希望现在一切顺利(格式化)
  • 你添加了一个代码块,是的。但是现在您的代码缩进过多,带有随机双引号,并且您的回溯实际上格式不正确。请再看一遍,这次要小心。

标签: python numpy opencv pycharm video-processing


【解决方案1】:

原因是该函数提供的图像比预期的要小。调整图像大小解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-19
    • 1970-01-01
    • 2021-02-16
    • 2022-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多