I’m trying to get first frame and keep it unchanged but it changes after every assignment to the other variable ( currImage = cv.QueryFrame(capture) ). What am I doing wrong?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cv
cv.NamedWindow("w1", cv.CV_WINDOW_AUTOSIZE)
#SET CAMERA INDEX BELOW
camera_index = -1
capture = cv.CaptureFromCAM(camera_index)
isRunning = True
firstImage = cv.QueryFrame(capture)
def repeat():
global capture #declare as globals since we are assigning to them now
global camera_index
global isRunning
global firstImage
c = cv.WaitKey(100) % 0x100
currImage = cv.QueryFrame(capture)
cv.ShowImage("w1",firstImage)
if(c==27):
isRunning = False
while isRunning:
repeat()
Let me quote you two passages from the opencv wiki, namely this page: http://opencv.willowgarage.com/documentation/python/reading_and_writing_images_and_video.html
What you are doing in your code not copying the object, you merely create another object pointing at the corresponding memory. Subsequent calls to the cvQueryFrame just modify the object, Therefor you have to copy it.
Try doing this: