cvloop icon indicating copy to clipboard operation
cvloop copied to clipboard

Not opening the video in linux.

Open piperod opened this issue 8 years ago • 1 comments

Hi, Thank you for this repo. I am experiencing problems opening the video in linux.

UserWarning: Attempting to set identical left==right results in singular transformations; automatically expanding. left=0, right=0 'left=%s, right=%s') % (left, right))

I think it has to do with this issue from openCV :https://github.com/ContinuumIO/anaconda-issues/issues/121

However I wanted to see if you have some solution or idea to solve it. Thanks in advance.

piperod avatar Nov 20 '17 20:11 piperod

Hi Ivan,

I don't know much what you can do apart from trying to uninstall opencv and installing it manually (without conda) then trying to link to the cv2.so it will create during installation. Installing OpenCV from source is usually very easy, though you might need to have to install:

git clone https://github.com/opencv/opencv.git
mkdir -p opencv/build
cd opencv/build
cmake ..  # for this step check out https://docs.opencv.org/3.3.0/dd/dd5/tutorial_py_setup_in_fedora.html which has details – make sure to use python3 though!
make -j8 install

Another possible way might be to "fake" the camera. However, there are few options. If you are only looking into modifying video files, the suggested scikit-video might be an option – note however, that it works different than mentioned in the issue you linked to (https://github.com/ContinuumIO/anaconda-issues/issues/121#issuecomment-55238785). I can also imagine that you can use pygame. I don't have a linux machine with a webcam at hand at the moment, so I will have to check the next few days if I can get it to work somewhere. But I can imagine that it's possible. To make this, either modify the cvloop.py source file directly by changing the import cv2 statement and the cv2.VideoCapture lines (maybe also the read line), or create a file cv2.py in which you create a class like below and populate it with the code depending on the library you choose. This file should be placed in the directory where your jupyter notebook is executed, or inside a directory which appears in your PYTHON_PATH before the real OpenCV's cv2.py. You can verify this simply by putting a print on top of the file.

# a) skvideo
import skvideo.io

# b) pygame
import pygame.camera

# Verify print
print('Using patched cv2.py!')

__version__ = '3.3.0'  # This is important to make cvloop believe you are using the correct OpenCV

class VideoCapture:
    def __init__(self, source):
        # a) skvideo, maybe source = '/dev/video0' even works for webcam
        self._source = skvideo.io.FFmpegReader(source)

        # b) pygame as suggested here https://stackoverflow.com/a/9712824/3004221
        pygame.camera.init()
        self._source = pygame.camera.Camera(pygame.camera.list_cameras()[source])
        self._source.start()

    def read():
        # a) skvideo
        return True, self._source.nextFrame()

        # b) pygame
        return True, self._source.get_image()

    def release():
        # a) skvideo
        self._source.close()

        # b) pygame
        self._source.stop()

Note that I just wrote this down, so I can not guarantee this to work, but it should give you some possible ways to solve the problem. Let me know if you get it to work!

shoeffner avatar Nov 21 '17 21:11 shoeffner