Ubuntu 18.04使用過程遇到的問題

pipy 下載numpy文件連接超時

pip3 install numpy 

始終出現連接超時錯誤,無法安裝,採用國內鏡像文件進行安裝。
錯誤說明:

requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://pypi.org/simple/requirements-txt/

解決方法:

pip3 install --index https://pypi.mirrors.ustc.edu.cn/simple/ numpy

使用conda pip 安裝文件出錯

報錯如下:

Cache entry deserialization failed, entry ignored

解決方法:

python -m pip install --upgrade pip   #未解決,出現連接超時
pip install --upgrade pip             #未解決,出現連接超時
pip install --index https://pypi.mirrors.ustc.edu.cn/simple/ --upgrade pip  #解決

opencv + python 無法關閉打開的窗口

代碼如下:

cv2.destroyWindows()

報錯如下

cv2.destroyWindows()
AttributeError: module 'cv2.cv2' has no attribute 'destroyWindows'

解決如下:

cv2.destroyAllWindows()

opencv + python 保存視頻出錯

 def write_video(output_path = "./testData/output.mp4"):
    #open the video 
    vid = cv2.VideoCapture('./testData/laneVideo1.mp4')
    # open the camera 
    # capture = cv2.VideoCapture(0) 
    if not vid.isOpened():
        raise IOError("couldn't open the video")

	
    video_FourCC_ori = int(vid.get(cv2.CAP_PROP_FOURCC))
    video_fourcc_mjpg = cv2.VideoWriter_fourcc(*"MJPG")
    video_FourCC = cv2.VideoWriter_fourcc(*"mp4v")

    video_fps = vid.get(cv2.CAP_PROP_FPS)
    video_size = (int(vid.get(cv2.CAP_PROP_FRAME_WIDTH)),int(vid.get(cv2.CAP_PROP_FRAME_HEIGHT)))
    isOutput = True if output_path != "" else False
    if isOutput:
        out = cv2.VideoWriter(output_path, video_Fourcc, video_fps, video_size)
    while True:
        ret, frame = vid.read()
        cv2.imshow("video",frame) 
        out.write(frame)
       
        key = cv2.waitKey(50)
        if key == ord('q'):
            break

    out.release()
    vid.release()
    cv2.destroyAllWindows()

存儲格式一:

video_FourCC_ori = int(vid.get(cv2.CAP_PROP_FOURCC))

報錯如下:

Could not find encoder for codec id 27: Encoder not found 

此時無法生成視頻文件
存儲格式二

video_fourcc_mjpg = cv2.VideoWriter_fourcc(*"MJPG")

報錯如下:

OpenCV: FFMPEG: tag 0x47504a4d/'MJPG' is not supported with codec id 7 and format 'mp4 / MP4 (MPEG-4 Part 14)'
OpenCV: FFMPEG: fallback to use tag 0x7634706d/'mp4v'

此時可以生成視頻文件,且能打開視頻文件,但運行時出現錯誤
存儲格式三

video_FourCC = cv2.VideoWriter_fourcc(*"mp4v")

此時能正常生成文件,問題解決。
TODO List

  1. fourcc 格式是否由於 指定.mp4 存儲文件 限制,導致報錯?
  2. 存儲其他格式的視頻文件?

numpy版本過高,出現警告

W0407 11:42:31.970886 7783 warnings.py:99] /home/df/anaconda3/envs/tf-cpu-cp36/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:495: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])

W0407 11:42:31.971002 7783 warnings.py:99] /home/df/anaconda3/envs/tf-cpu-cp36/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:496: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])

W0407 11:42:31.971152 7783 warnings.py:99] /home/df/anaconda3/envs/tf-cpu-cp36/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:497: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])

W0407 11:42:31.971256 7783 warnings.py:99] /home/df/anaconda3/envs/tf-cpu-cp36/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:502: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])

import numpy as np
np.__version__

輸出

1.18.2

解決方法

pip uninstall numpy
pip install numpy==1.16.0
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章