1

I want to take a photo when the user press 's'. This is my code and I don't find why it's wrong.

import cv
import sys

win = 'Camera'
cv.NamedWindow(win)
cap = cv.CreateCameraCapture(0)


while cv.WaitKey(1) != 27:
img = cv.QueryFrame(cap)

cv.ShowImage(win, img)
if cv.WaitKey(10) == 115:
cv.SaveImage('test1.jpg', img)

The mistake said:

File "dos.py", line 14 cv.SaveImage('test1.jpg', img) ^ IndentationError: expected an indented block

Margarita Gonzalez
  • 1,127
  • 7
  • 20
  • 39

1 Answers1

1

Since you did not tell us what the problem is, I'm going to guess that the camera failed to initialize.

The obvious problem is... you need to start coding safely!!! Test the return of the calls whenever possible:

cap = cv.CreateCameraCapture(0)
if not cap:
    print("!!! Failed CreateCameraCapture: invalid parameter!")

EDIT:

Now that you shared what the problem is, I suggest you indent the code since Python uses the indentation of the code to figure out where a block of code begins and ends.

You can also specify the filename with double quotes:

if cv.WaitKey(10) == 115:
    cv.SaveImage("test1.jpg", img)
Community
  • 1
  • 1
karlphillip
  • 92,053
  • 36
  • 243
  • 426