小编RoY*_*RoY的帖子

使用python和opencv保存视频时出错

这是从网络摄像头保存视频的代码

import numpy  
import cv2 
cap = cv2.VideoCapture(0)

# Define the codec and create VideoWriter object 
fourcc = cv2.VideoWriter_fourcc(*'XVID')  
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
        frame = cv2.flip(frame,0)
        # write the flipped frame
        out.write(frame)
        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

cap.release() 
out.release() 
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

当我运行它在python中它给出以下错误

> raceback (most recent call last):    File
> "C:\Users\Prakash\Desktop\Image Proccessing\c.py", line 6, in <module>
> fourcc = cv2.VideoWriter_fourcc(*'XVID')  AttributeError: 'module'
> object has no attribute 'VideoWriter_fourcc' …
Run Code Online (Sandbox Code Playgroud)

python opencv video-capture image-processing

1
推荐指数
1
解决办法
9639
查看次数

逐行打印python列表中的列表

我使用以下代码创建了一个列表

grid = [['a' for i in range (0,5)]  for j in range (0,3)]
print grid 
Run Code Online (Sandbox Code Playgroud)

代码的输出是

[['a', 'a', 'a', 'a', 'a'], ['a', 'a', 'a', 'a', 'a'], ['a', 'a', 'a','a', 'a']]
Run Code Online (Sandbox Code Playgroud)

我想在表单中显示此列表

 [['a', 'a', 'a', 'a', 'a'], 
  ['a', 'a', 'a', 'a', 'a'],
  ['a', 'a', 'a', 'a', 'a']]
Run Code Online (Sandbox Code Playgroud)

我应该做些什么改变来获得这个输出

我正在使用python 2.7

我不想导入任何额外的模块

python python-2.7

-1
推荐指数
1
解决办法
42
查看次数

将numpy二维数组转换为列表

我有一个数组

r = np.zeros((5,6))
print r
Run Code Online (Sandbox Code Playgroud)

其输出是

[[ 0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.]] 
Run Code Online (Sandbox Code Playgroud)

我想将此数组中的值分配给列表,所以我按名称网格创建了一个列表

grid1 = [['a' for i in range (0,6)]  for j in range (0,5)]
print grid1
Run Code Online (Sandbox Code Playgroud)

其输出是

[['a', 'a', 'a', 'a', 'a', 'a'], ['a', 'a', 'a', 'a', 'a', 'a'], ['a', 'a', 'a', 'a', 'a', 'a'], ['a', 'a', 'a', …
Run Code Online (Sandbox Code Playgroud)

python python-2.7

-2
推荐指数
1
解决办法
1584
查看次数