当前位置:   article > 正文

求助,cv2.error: OpenCV(4.9.0) :-1: error: (-5:Bad argument) in function ‘line‘

求助,cv2.error: OpenCV(4.9.0) :-1: error: (-5:Bad argument) in function ‘line‘

我的代码

  1. with open("video.txt",'r',encoding='utf-8') as file:
  2. #video1=[]
  3. number1=[]
  4. number2 = []
  5. number3 = []
  6. number4 = []
  7. for i in file:
  8. #video1.append(i)
  9. n1=''
  10. n2=''
  11. t=0
  12. for j in i :
  13. #print(type(j))
  14. #print(type('[\s]'))
  15. if j !=" " and t == 0:
  16. n1 = n1 + j
  17. elif j ==" " and t == 0:
  18. t = 1
  19. elif j !=" " and t == 1:
  20. n2 = n2 + j
  21. elif j ==" " and t == 1:
  22. break
  23. number1.append(int(n1))
  24. number2.append(int(n2))
  25. for l in range(0, number1[len(number1)-1]):
  26. number3.append(0)
  27. number4.append(0)
  28. m =0
  29. for k in range(0, len(number1)-1):
  30. number3[number1[k]-1] = number3[number1[k]-1] + 1
  31. for k in range(0, len(number1)-1):
  32. if number2[k] > m:
  33. number4[number1[k]-1] = m
  34. # number3是每帧的人数,number4是累计人数
  35. import cv2
  36. import numpy as np
  37. lx = 1000
  38. ly = 1000
  39. image = np.zeros([lx,ly,0],dtype = np.uint8)
  40. #image=np.ascontiguousarray(image)
  41. for k in (1, len(number1)-1):
  42. #人流变化
  43. cv2.line(image,(k - 1,ly-number3[k-1]),(k,ly-number3[k]),(255,0,0),2)
  44. #累计人数
  45. cv2.line(image,(k - 1,ly-number4[k-1]),(k,ly-number4[k]),(0, 255,0),2)
  46. cv2.imshow("image", image)
  47. cv2.waitKey()

主要相关代码

  1. import cv2
  2. import numpy as np
  3. lx = 1000
  4. ly = 1000
  5. image = np.zeros([lx,ly,0],dtype = np.uint8)
  6. #image=np.ascontiguousarray(image)
  7. for k in (1, len(number1)-1):
  8. #人流变化
  9. cv2.line(image,(k - 1,ly-number3[k-1]),(k,ly-number3[k]),(255,0,0),2)
  10. #累计人数
  11. cv2.line(image,(k - 1,ly-number4[k-1]),(k,ly-number4[k]),(0, 255,0),2)
  12. cv2.imshow("image", image)
  13. cv2.waitKey()

我的报错

  1. Traceback (most recent call last):
  2. File "F:\建院\大二\srtp天眼识迹\pic\main.py", line 52, in <module>
  3. cv2.line(image,(k - 1,ly-number3[k-1]),(k,ly-number3[k]),(255,0,0),2)
  4. cv2.error: OpenCV(4.9.0) :-1: error: (-5:Bad argument) in function 'line'
  5. > Overload resolution failed:
  6. > - Layout of the output array img is incompatible with cv::Mat
  7. > - Expected Ptr<cv::UMat> for argument 'img'

翻了一些文章说是mat不连续,要用np.ascontiguousarray()函数,但是我作为小白研究不明白,在文中注释的地方插入,还是相同的报错。 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/205711
推荐阅读
相关标签
  

闽ICP备14008679号