i tried to modify the code in darknet.py to do detections in live video feed coming from the webcam. Just imported open cv library and did a bit of modifications in the main function. It was previously detecting single images i.e before importing opencv. But now i get this error. Can anyone please help ..
Error:
(python:7913): Gtk-ERROR **: GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported
Trace/breakpoint trap (core dumped)
My main function looked like this :
if name == "main":
net = load_net("cfg/yolov3.cfg", "yolov3.weights", 0)
meta = load_meta("cfg/coco.data")
cap = cv2.VideoCapture(0)
while(True):
ret, frame = cap.read()
cv2.imshow('frame',frame)
cv2.imwrite('check.jpg',frame)
r = detect(net, meta, "check.jpg")
print r
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
Related
I want to read video from webcam with helps opencv on python but I have next error:
'NoneType' object has no attribute 'shape'.
In console I have: [ WARN:0] videoio(MSMF): can't grab frame. Error: -2147483638
print("starting video stream...")
vs = VideoStream(src=0).start()
time.sleep(2.0)
while True:
frame = vs.read()
frame = imutils.resize(frame, width=600) #'NoneType' object has no attribute 'shape'
if W is None or H is None:
(H, W) = frame.shape[:2]
cv2.imshow("Frame", frame)
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
cv2.destroyAllWindows()
vs.stop()
Hay can I solve this problem? Thanks!
the default MSMF api for camera wasnt working for me with opencv 4.2.0.34, but works for opencv 3. switching to DSHOW api worked
cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
I have noticed the issue was resolved using the following steps (found here):
I managed to get around the issue, I uninstalled the LM driver via
Device Manager, and reinstalled. I also made sure the LM Control Panel
app was NOT running. Now, it seems to work fine. Not sure which fixed
it.
I would like to lunch a usb-camera at my raspberry pi, but when I try to start python code (opencv), it shows this message and stop a lunch
ASSERT: "false" in file qasciikey.cpp, line 501
Aborted
Can someone please explain me, what error is this?
It doesnt work even with another codes as well... But camera works fine, when I open it in programs like Camorama webcam viewer. I read that this part makes a problem
cv2.waitKey(20)
So it makes in another code (when i uncomment it, it lunch the code but dont show camera output) But in this code, even if I uncomment it, the code themself doesn't work: show upper error message
Here is the code
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_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',frame)
cv2.imshow('gray',gray)
if cv2.waitKey(20) & 0xFF == ord('q'): # HERE
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
oh are you Japanese yes bro computers are little racist do not press any japanese letter while your code runing. for waitKey you can use esc or number keys:
if cv2.waitKey(20) & 0xFF == ord('0'):
break
This is the code when i execute it:
You can see the frame opens but doesnt show anything
I want to use a usb camera with a raspberry pi 3 model b v1.2 using opencv 3.3 and python 2.7.
I work with opencv in an virtual enviroment.
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
ret, frame = cap.read() #Capture frame-by-frame
#Our operations on the frame come here
#gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#Display resulting frame
cv2.imshow('frame',frame)
cv2.waitKey(10)
#if cv2.waitKey(1) & 0xFF == ord('q'):
# break
#when everything done, release the capture
cap.release()
cv2.destroyAllWindows()
I just have no idea how to get around this error. I already searched the error and i am getting helpless, anyone having an idea?
EDIT: i am currently playing around with the code and i can get frames but most of the time the screen stays grey. I use # to show how the code looks now
Ok, it now opens a window and shows the output of the camera
Because of this code:
import sys
sys.path.append('/home/pi/.virtualenvs/cv/lib/python2.7/site-
packages/usr/local/lib/python2.7/site-packages')
and i also use sudo python program.py in the terminal
But this Error :"NameError: name 'CV_CAP_PROP_FRAME_HEIGHT' is not defined" still persists...
I'm writing a program in python using OpenCV which detects the edges (Canny Edge Detector) from the footage my webcam records. I'm also using two track-bars in order to control the threshold values (in order for to understand how these values change the output of this edge detector).
The code I wrote is the following:
import cv2
import numpy as np
def nothing(x):
pass
img = np.zeros((300,512,3), np.uint8)
cv2.namedWindow('cannyEdge')
cv2.createTrackbar("minVal", "cannyEdge", 0,100, nothing)
cv2.createTrackbar("maxVal", "cannyEdge", 100,200,nothing)
cap = cv2.VideoCapture(0)
while(True):
minVal = cv2.getTrackbarPos("minVal", "cannyEdge")
maxVal = cv2.getTrackbarPos("maxVal", "cannyEdge")
#capture frame by frame
ret, frame = cap.read()
cv2.imshow('frame', frame)
edge = cv2.Canny(frame,minVal,maxVal)
#display the resulting frame
cv2.imshow('frame', edge)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
#When everything is done, release the capture
cap.release
cv2.destroyAllWindows()
This program is for educational purposes only as I'm currently learning to use OpenCV.
Every time I run the program above the code seems to be working just fine but I get the following Error:
GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
I've searched for the reason this error occurs but I haven't found anything helpful. My instinct tells me that my implementation for the trackbars is wrong and thus it's causing this error.
The tutorials I used are the following:
OpenCV tutorials - Canny Edge Detector
OpenCV tutorials - Trackbars
Does anybody know why this error occurs? Any help will be appreciated!
I am running Ubuntu 14.04, OpenCV 3.2.0 and Python 2.7.6
Try making the track bars and displaying the image in the same window and see if the error persists. I bet it shouldn't. Change: cv2.imshow('cannyEdge', edge)
Have you created another window named "frame"? If not, it looks like you should change 'frame' to 'cannyEdge':
cv2.imshow('cannyEdge', frame)
There are already many questions exist regarding cv2.VideoCapture but it doesn't help me.
I am using OpenCV 2.4.10 and python 2.7.9 , I am trying to capture video from built-in webcam (Toshiba ,Windows 7) . I am using this code
import numpy as np
import cv2
cap = cv2.VideoCapture(1)
print cap.isOpened()
print cap.get(3)
print cap.get(4)
while(True):
ret,frame=cap.read()
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
And the problem is , When i first run this code it throws error : error: (-215) size.width>0 && size.height>0 in function cv::imshow
and just after waiting for hardly one minute , i again run this code and this time it's fine
And this is happening again and again , sometimes it's work good but sometimes fails and give error. Any solution to this ?
I copied the opencv_ffmpeg2410.dll file from C:\Applications\opencv\build\x86\vc10\bin into the python path C:\Python27(OpenCV 2.4 VideoCapture not working on Windows)
I tried cv2.VideoCapture(0) but in this case web-camera didn't even start (web-camera light did not blink)
Since you are not checking the value of the ret return value, it is possible that cap.read() is giving you a bad frame.
Replace with something like
while True:
ret, frame = cap.read()
if ret:
cv2.imshow('window', frame)
# ...