Giter Club home page Giter Club logo

Comments (6)

jrobchin avatar jrobchin commented on July 21, 2024

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!

from computer-vision-basics-with-python-keras-and-opencv.

nickkchenn avatar nickkchenn commented on July 21, 2024

Thank you.

  1. 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.

  2. My OS is win10 , and I run the Getting Key Pressed snippet and 's' can be recongnized and is numbered as 115.

  3. 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.

  1. 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.

  2. BTW,I really like your work of this notebook, I learnt a lot from it as a beginner,thank you very much

from computer-vision-basics-with-python-keras-and-opencv.

nickkchenn avatar nickkchenn commented on July 21, 2024

There a two messages I don't know whether they are relevant

  1. 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"
    like this
    not trusted

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:
assertion

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.

  1. I'm not sure whether above messages are useful , just for your reference.

from computer-vision-basics-with-python-keras-and-opencv.

jrobchin avatar jrobchin commented on July 21, 2024

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.

from computer-vision-basics-with-python-keras-and-opencv.

nickkchenn avatar nickkchenn commented on July 21, 2024

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!

from computer-vision-basics-with-python-keras-and-opencv.

jrobchin avatar jrobchin commented on July 21, 2024

Nice, it's weird that it wouldn't throw an error when you did that. Enjoy!

from computer-vision-basics-with-python-keras-and-opencv.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.