查看: 1530|回复: 1

Opencv中不支持的数组类型错误

[复制链接]

10

主题

57

帖子

143

积分

注册会员

Rank: 2

积分
143
发表于 2018-10-12 17:29:27 | 显示全部楼层 |阅读模式
本帖最后由 lovelylucky 于 2018-10-13 10:19 编辑

小菜鸟一枚,确定所有的的东西都正确安装了但是当我想绘制图像时:例如:这段代码取自Python openCV tutoria
  1. import numpy as np
  2. import cv2
  3. # Create a black image
  4. img = np.zeros((512,512,3), np.uint8)
  5. # Draw a diagonal blue line with thickness of 5 px
  6. img = cv2.line(img,(0,0),(511,511),(255,0,0),5)
  7. cv2.imshow('img',img)
  8. cv2.waitKey(0)
  9. cv2.destroyAllWindows()
复制代码
却得到了如下错误:
  1. OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /build/buildd/opencv-2.3.1/modules/core/src/array.cpp, line 2482
  2. Traceback (most recent call last):
  3. File "/home/dccv/rec 2.py", line 17, in <module>
  4. cv2.imshow('img',img)
  5. cv2.error: /build/buildd/opencv-2.3.1/modules/core/src/array.cpp:2482: error: (-206)
  6. Unrecognized or unsupported array type in function cvGetMat
复制代码
在window和ubuntu同样都有这样的错误



回复

使用道具 举报

5

主题

53

帖子

130

积分

注册会员

Rank: 2

积分
130
发表于 2018-10-12 17:33:20 | 显示全部楼层
本帖最后由 AI的世界 于 2018-10-13 10:20 编辑

第6行:不将img变量设置为返回值,而是忽略返回值
  1. import numpy as np
  2. import cv2
  3. # Create a black image
  4. img = np.zeros((512,512,3), np.uint8)
  5. # Draw a diagonal blue line with thickness of 5 px
  6. cv2.line(img,(0,0),(511,511),(255,0,0),5)
  7. cv2.imshow('img',img)
  8. cv2.waitKey(0)
  9. cv2.destroyAllWindows()
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表