So I'm just trying to run the basic OpenCV program
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA)
# Display the resulting frame
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
But for some reason when I try to run it (with python 2 or 3) I get this weird abort statement
[1] 74309 abort python3 index.py
(I'm guessing the 5 digit number is the PID) However, it does work if I pass in a path to an already existing video in the VideoCapture function. I am a beginner in all of this so I'm not really sure what the problem is
Thanks :)
I found the solution!
I tried running the script using the default terminal that comes with mac and it worked :) So it seems there was some weird issue with the third party terminal (iTerm) I was using
You have to authorize iTerm to access the camera (in System Preferences). By default, neither Terminal nor iTerm has this permission. macOS Mojave just asks to allow iTerm and your Python program works fine!
It's not a problem with iTerm, or maybe was a problem.
I had the same problem running OpenCV from VSCode. It turned out to be indeed permission error for accessing the camera on the new macOS. I couldn't get VSCode to ask for the permission (or add it manually through system preferences).
My solution was to run VSCode as root using
sudo /Applications/Visual Studio Code.app/Contents/MacOS/Electron
It's not the cleanest solution, but it worked for me.
In VSCode ,
1.type cmd+shift+p
2.type "shell command: Install code in PATH"
3. Close vscode
4. Use "sudo code" to open vscode
5. It will give warning not to run as a root user
6. Ignore the warning and run the file , you will not get the "Abort trap: 6" error anymore.
Related
The following code has now started to return an error to me:
cv2 import
capture = cv2.VideoCapture(1)
capture.release()
return
[ WARN:0] global /tmp/pip-req-build-qacpj5ci/opencv/modules/videoio/src/cap_v4l.cpp (893) open VIDEOIO(V4L2:/dev/video1): can't open camera by index
I have a video grabber connected and I had no problems with it earlier.
I don't see '/dev/video1' on my computer, but I see only '/dev/video0'.
From the information I found on the Internet, it seems to me that the most probable reason is that I did not close the capturing device.
I use ubuntu 18.04, python 3.6.9 and opencv-python===4.4.0.46.
I was running the code with jenkins as sudo (and sometimes the job was stopped manualy).
I tried to restart the computer and some other things I found on the Internet, but unfortunately nothing helped.
I'll add that at first I also couldn't run the webcam script in the computer (i.e. with parameter 0), but after some time I succeeded (in the meantime I was whisking some suspicious processes).
I have recently upgraded my MacBook to run Catalina. This seems to have broken webcam access to secondary processes.
The following code ran like a charm on Mojave but won't let me access the webcam in the secondary process.
#!/usr/bin/env python3
from multiprocessing import Process
import cv2
def capture_cam(process):
cap = cv2.VideoCapture(0)
(ret, frame) = cap.read()
print(process, ret)
p_cam = Process(target=capture_cam, args=['Secondary'])
p_cam.start()
p_cam.join()
capture_cam('Primary')
The output under Catalina is
$ export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
$ python test.py
Primary True
The problem is very curious to me. I guess it has something to do with the new privacy settings in 10.15.
I have a project written in Python to capture the video of my webcam camera using opencv.
When i run this file it had an eror:
Error running 'Capture_image': Cannot run program"C:/Python/python.exe"(in directory"D:/Vien/Python/Python Program"): CreateProcess error = 2, specified file could not be found
Before this I've install 2 version of Python that is Python 3.8.2 and Python 3.6.8 and set up the interpreter with Python 3.6.8 and the link is " C:/Python 3.6.8 64bit/Python.exe "
Moreover, when I install Python I've install the Python 3.8.2 version first and create a directory to put it in disk C with file" Python" then I changed the name into "Python 3.8.2"
So I don't know what caused this error and how to fix this.
Can anyone realize what mistake I've made?
Thank you!
Here is the code( But I don't think the code caused this error):
import cv2
cap = cv2.VideoCapture(0)
while(True):
ret,frame = cap.read()
cv2.imshow('frame', frame)
cv2.waitKey(5)
cap.release()
I am trying to install OpenCv and run some code on PyCharm on Mac.
I have installed the opencv package as well as numpy but when I run the code this error shows up on Pycharm IDE: "cannot find reference 'VideoCapture' in __init__.py"
In fact, every time I write example_variable = cv2., PyCharm is not giving me any option to autocomplete with a function attached to cv2. Why is this happening?
Here's the code I am trying to run. I tried also running other codes but the same error displays:
import cv2
import numpy as np
cap = cv2.VideoCapture()
while True:
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & OxFF == ord('q'):
break
cap.release
cv2.destroyAllWindows()
Any tips on how to run this code smoothly? The end goal is to have my front webcam capture live video and react to it.
Try one of this solutions:
Right-click on source Directory
Mark Directory as -> source root
File --> Invalidate Caches / Restart... -> Invalidate and Restart
OR:
In your IDE, go to settings -> preferences -> django
Ensure your Root directory, your settings.py and your manage.py are in the right place
if you are in Django.
After all that, you can also delete the .idea folder in your root directory and restart the IDE.
pip install --force-reinstall --no-cache -U opencv-python==4.5.5.62
use this command line to avoid the reference issue.
Instead of import cv2 use from cv2 import cv2
I agree with "from cv2 import cv2"
there have an another way to solve problems:
** Do Not Use Pip Install **
I try to use download opencv_python-4.5.5.62-cp36-abi3-win_amd64.whl file and then manual double click to install
wait a minute, Pycharm IDE successfully Show code completion.
by the way,can your code run?
if code can run, above will help you a bit.
and your path(project python) should be Englisgh ; not be Chinese or other language.
This worked for
Before I was using python from Anaconda, instead
Choose the default python interpreter
I have attached an usb camera with raspberry pi and also enable it using sudo raspi-config command . I rebooted the raspberry pi after enabling it, but it doesn't enable - so getting error (error is..mmal: Camera is not detected. Please check carefully the camera module is installed correctly)
When run command (raspistill -o image.jpg) to capture an image, I have also run update and upgrade command to update raspberry pi but doesn't solve problem.
And main thing when I run ffnpng -i /dev/video video.avi, it records video so camera working so why this error coming? And what is the solution for that.
Is there any other way or command to cature image? plz help me. Thank u in advance.
Have you installed the fswebcam module? You can get it using:
sudo apt-get install fswebcam
Images are taken using the command fswebcam <image_name>.jpg
A full tutorial can be found here from raspberrypi.org.
It looks like the problem is the connection between camera module and Raspberry PI CSI interface. Check if the CSI cable is correctly connected to CSI interface on the Raspberry PI board or try to unplug camera cable and plug it again.
raspistillyuv and raspistill are official image capturing programs for the camera module: link
USB cameras are not mounted under mmal (Only CSI). Try running v4l2-ctl --list-devices to see if your camera is mounted correctly. You will see there is a /dev/videoX like string under your camera if it's mounted correctly. Use that X value to access the camera.
As an example, in OpenCV(Python) you can capture an image as bellow,
import cv2
cap = cv2.VideoCapture(X)
ret, frame = cap.read()
cv2.imwrite("image_name.jpg",frame)
cap.release()