TypeError:dst不是一个numpy数组,也不是标量

时间:2017-05-25 02:24:27

标签: python opencv

我在python脚本中使用anaconda2,但它向我展示了这些错误信息:

Traceback (most recent call last):
  File "main.py", line 16, in <module>
     clip = source.fl_image(lane_detector.run)
  File "E:\Anaconda2\Lib\site-packages\moviepy\video\VideoClip.py", line 533, in                                                                fl_image
     return self.fl(lambda gf, t: image_func(gf(t)), apply_to)
  File "E:\Anaconda2\Lib\site-packages\moviepy\Clip.py", line 136, in fl
     newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
  File "<decorator-gen-57>", line 2, in set_make_frame
  File "E:\Anaconda2\Lib\site-packages\moviepy\decorators.py", line 14, in outpl                                                               ace
     f(newclip, *a, **k)
  File "E:\Anaconda2\Lib\site-packages\moviepy\video\VideoClip.py", line 694, in                                                                set_make_frame
     self.size = self.get_frame(0).shape[:2][::-1]
  File "<decorator-gen-14>", line 2, in get_frame
  File "E:\Anaconda2\Lib\site-packages\moviepy\decorators.py", line 89, in wrapp                                                               er
     return f(*new_a, **new_kw)
  File "E:\Anaconda2\Lib\site-packages\moviepy\Clip.py", line 95, in get_frame
     return self.make_frame(t)
  File "E:\Anaconda2\Lib\site-packages\moviepy\Clip.py", line 136, in <lambda>
     newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
  File "E:\Anaconda2\Lib\site-packages\moviepy\video\VideoClip.py", line 533, in                                                                <lambda>
     return self.fl(lambda gf, t: image_func(gf(t)), apply_to)

  File "C:\Users\shihaohou\Desktop\lane-line-detection-master\detector.py", line                                                                655, in run
     warped = self.__perspective_transform(preprocessed,pers_mat)
  File "C:\Users\shihaohou\Desktop\lane-line-detection-master\detector.py", line                                                                328, in __perspective_transform
    warped = cv2.warpPerspective(img, mat, img_size, cv2.INTER_LINEAR)
    TypeError: dst is not a numpy array, neither a scalar

detetor.py中的相关代码是:

def __perspective_transform(self, img, mat):
    '''
    Method to transform the image
    :param img: the image to be transformed
    :param mat: the perspective matrix
    :return: the transformed image
    '''
    img_size = (img.shape[1], img.shape[0])
    warped = cv2.warpPerspective(img, mat, img_size, cv2.INTER_LINEAR)

    return warped

if self.ENABLE_LOGS:
        cv2.imwrite('./test/def_' + str(self.processed_frames) + '.jpg', img)

    # undistort the image using the calibrated values
    undistorted = self.__undistort(img,self.mtx, self.dist)

    # pass the distortion corrected image through the threshold pipeline
    preprocessed = self.__prepocess(undistorted)

    if self.ENABLE_LOGS:
        cv2.imwrite('./debug/preprocessed_' + str(self.processed_frames) + '.jpg', img)

    # get the current region of interest and load the perspective and inverse perspective matrix
    src, dest = self.__get_current_roi()
    pers_mat, inv_mat = self.__load_perspective_matrix(src, dest)

    # transform the thresholded image to a bird's eye view
    warped = self.__perspective_transform(preprocessed,pers_mat)

我查看了cv2.warpPerspective函数,这个错误意味着这个函数没有正确使用吗?谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

您需要将其称为:

warped = cv2.warpPerspective(img, mat, img_size, flags=cv2.INTER_LINEAR)