Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6204359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:04:38+00:00 2026-05-24T05:04:38+00:00

I am trying to capture image from a webcam when a key is hit.

  • 0

I am trying to capture image from a webcam when a key is hit. Following code is successful

    import cv

    cv.NamedWindow("w1")
    camera = cv.CaptureFromCAM(-1)

    while True:

        key = cv.WaitKey(0);

        if key == 'q': 
            break;
        image = cv.QueryFrame(camera)
        cv.ShowImage("w1", image)


    cv.DestroyWindow("w1")

It works fine for the first keypress. For the next keydown it shows a frame very close to the first one even if you moved. After several key presses it changes to the actual image. What i can infer is that, there is some kind of buffer where frames are stored
I am wondering if someone could please help me in getting the precise frame when a key is being hit.

I am using opencv with interface to python. The operating system is ubuntu 11.04. The calls for capture frame are sent to v4l library. I have an integrated webcam with my dell laptop.

I am wondering if someone can help me with this issue.

Thanks a lot

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:04:38+00:00Added an answer on May 24, 2026 at 5:04 am

    I suggest you try it in a slightly different manner:

    import cv
    
    cv.NamedWindow("w1")
    camera = cv.CaptureFromCAM(-1)
    
    while True:
        image = cv.QueryFrame(camera)
        key = cv.WaitKey(33)
    
        if key == 'q':
            break
        elif key != -1:
            cv.ShowImage("w1", image)
    
    cv.DestroyWindow("w1")
    

    Notice the change in the call to cv.WaitKey(): instead of blocking on it, just wait for a reasonable time. Then check if a key was actually pressed (key != -1).

    I should note that your code worked on my Mac OS X 10.6 with OpenCV 2.3.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to open camera from my android application and capture image, but
I am trying to capture video from a camera. i have gotten the captureOutput:didOutputSampleBuffer:
I'm trying to capture an image from the window mobile device using Qt. Is
I have been trying to implement this code , where i capture a image
I am trying to invoke camera from HTML5 and JavaScript. My code is as
I am trying to implement Camera application in android,and i got some code from
I am trying to capture from a Sony Handicam DCR-HC38, running the code below,
I am trying to use the following code to take screen shots from my
I'm trying to do an image capture on a high end Nokia phone (N95).
I am trying to capture output from an install script (that uses scp) and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.