调用cv2.rectangle时无法绘制框

时间:2018-03-30 08:37:15

标签: numpy opencv

在opencv中翻转后无法在图像上绘制框。

>>im = cv2.imread('demo.jpg')
>>im = im[:,::-1]
>>drawed_im = cv2.rectangle(im, (10,10), (50,50), (255, 0, 0), thickness=2)
>>TypeError: Layout of the output array img is incompatible with cv::Mat (step[ndims-1] != elemsize or step[1] != elemsize*nchannels)

1 个答案:

答案 0 :(得分:1)

这是一个奇怪的,我无法确定原因。我之前已经看过其他绘图函数,我使用的解决方案是将图像重新转换为numpy数组。

symbol = "AAPL"
d = {}
for i in range(level+1):
  name = 'accounting_price_{}'.format(symbol)
  d[name] = {}
  d[name][i] = yahoo_prices[j]['accg'][i][0]