2019-06-02 Python-随手记

1. python2 两个int整数相除,结果仍旧是整数,例如

3/4
0

因为自己clone的工程中需要用两个int相除得到float型的数,而自己的conda环境又是python2.7的,所以只能寻求其他解决方案。
解决路径如下

https://blog.csdn.net/yygydjkthh/article/details/39377265

解决方法:
在代码的第一行加入如下语句(注意一定是代码的第一行,不然会报错)即可:
from __future__ import division

2. 跑yolo v3,识别视频,可以正常识别但是无法存储

报错信息如下:

Traceback (most recent call last):
  File "yolo_video.py", line 75, in 
    detect_video(YOLO(**vars(FLAGS)), FLAGS.input, FLAGS.output)
  File "/home/sjt/Tensorflow/keras-yolo3/yolo.py", line 195, in detect_video
    image = Image.fromarray(frame)
  File "/home/sjt/anaconda2/envs/tf/lib/python2.7/site-packages/PIL/Image.py", line 2483, in fromarray
    arr = obj.__array_interface__
AttributeError: 'NoneType' object has no attribute '__array_interface__'

我使用的是keras-yolo-v3,工程地址如下:

https://github.com/qqwweee/keras-yolo3

在issue中找到了解决方案,链接如下:

https://github.com/qqwweee/keras-yolo3/issues/269

具体为:

I had the same two problems. To fix it, I made the following changes to yolo.py:
On line 177, change:
video_FourCC = int(vid.get(cv2.CAP_PROP_FOURCC))
to
video_FourCC = cv2.VideoWriter_fourcc(*"mp4v")
This definitely works with .mp4 and .mov file types, possibly other types too.
Immediately after line 190, add:

if not return_value:
   break

注意,我检测的视频格式是.mp4的,所以video_FourCC处对应的是 *‘mp4v’,如果是其他格式请自行google/百度

你可能感兴趣的:(2019-06-02 Python-随手记)