Closed nickkchenn closed 6 years ago
One thing I would make sure to check is that you're focused on the OpenCV window that shows the webcam feed. Key presses are only registered if you are.
I also had to develop this on Windows for the lecture, so it may be an OS thing. I would use the Getting Key Presses snippet to make sure that the s key is being recognized and correctly numbered (115 for the Collecting Data section):
while True:
# Placeholder frame to show window
window = np.zeros((300,300))
# Display result
cv2.imshow("frame", window)
k = cv2.waitKey(1) & 0xff
if k != 255: # A key is pressed
print(k)
if k == 27:# escape pressed
break
cv2.destroyAllWindows()
video.release()
Can you also elaborate on the second part? You say that it works successfully, so I may be missing the issue. Any other info you can give me will also be helpful in debugging your issue, thanks!
Thank you.
I make sure that I focused on the webcam feed window,but I still can't save the capture. When I press 's',nothing happens.
My OS is win10 , and I run the Getting Key Pressed snippet and 's' can be recongnized and is numbered as 115.
In the second part, I meant I wrote a new program like below:
video = cv2.VideoCapture(0)
while True:
success, frame = video.read()
if not success:
# Frame not successfully read from video capture
break
# Display result
cv2.imshow("frame", frame)
k = cv2.waitKey(1) & 0xff
if k == 27:# escape pressed
break
elif k == 115: # s pressed
#fname = input("File name")
fname = 'test'
cv2.imwrite(os.path.join( '{}.jpg'.format(fname)), frame)
cv2.destroyAllWindows() video.release()
It worked when I pressed 's' , a capture was saved.
4. So I'm still confused why it just won't work in the Collecting Data part
I searched my whole computer and made sure that there was no capture saved.
5. BTW,I really like your work of this notebook, I learnt a lot from it as a beginner,thank you very much
There a two messages I don't know whether they are relevant
I didn't think it's a big deal and jsut left it there
2.When I run the "Tracking Hand" part , I notice that if I move my hand partially out of the camera , an error message from OpenCV about "assertion failed " will appear, like this:
I think that's because when I move my hand out of the cam partially , part of the box is out of the range of the picture,so the error about memory/boundary is triggered.
The tracking works fine despite these error messages.
In the second part, I meant I wrote a new program like below:
video = cv2.VideoCapture(0)
while True:
Read a new frame
success, frame = video.read() if not success: # Frame not successfully read from video capture break # Display result cv2.imshow("frame", frame) k = cv2.waitKey(1) & 0xff if k == 27:# escape pressed break elif k == 115: # s pressed #fname = input("File name") fname = 'test' cv2.imwrite(os.path.join( '{}.jpg'.format(fname)), frame)
cv2.destroyAllWindows() video.release() It worked when I pressed 's' , a capture was saved.
If this works, then it may be a problem with the path that I've set the images to save to. In Collecting Data, try to manually set a relative path instead and see if that fixes it.
BTW,I really like your work of this notebook, I learnt a lot from it as a beginner,thank you very much
Thanks, I hope you're able to get a head start with this! The whole goal was to give beginners the knowledge I wish I had when I started.
I run the jupyter notebook from the command line , and every time it is autosaved , it showed that "Notebook CVPY/Computer-Vision-Basics-with-Python-Keras-and-OpenCV.ipynb is not trusted"
This should not be a problem as far as I know. If I remember correctly you may be able to click the button that says untrusted in the top right corner to trust it, but don't quote me on that.
When I run the "Tracking Hand" part , I notice that if I move my hand partially out of the camera , an error message from OpenCV about "assertion failed " will appear, like this:
This is because I'm cropping the hand region and when your hand is not in frame, it cannot draw a 0 width and 0 height window. I'll add this to my todo list to fix.
I'm not sure whether above messages are useful , just for your reference.
These are ALWAYS useful, thanks for all the input!
I'd also check that you have set the read and write permissions correctly. I'm not too sure how to do this on Windows (I primarily develop on Linux), but I'm sure you can figure out how to do it with StackOverflow/Google-foo.
Problem solved! It is really the problem with path,I thought with os.path.join , new folders would be created automatically. Clearly,it wouldn't. I manually create the folder ,and captures are saved successfully in the folder. Thank you for your patient answering!
Nice, it's weird that it wouldn't throw an error when you did that. Enjoy!
I ran the notebook from the beginning,everything worked fine ,until the "Collecting data"part. When I ran the "Collecting data" cell, webcam was successfully opened and the hand tracking worked fine after pressing 't' .But when I press 's' ,there was no pics saved in any directory and there was no error or warning reported.
I start a new notebook to just open the webcam and press 's' to save a capture, it worked successfully. I don't know which part goes wrong here .