opencv 2 or 3 debugging? [closed]
I'm very interested in this code below taken from[this page] (http://opencvpython.blogspot.in/2012/...)
I try and run it but get the error:
cv2.accumulateWeighted(f,avg1,0.1)
TypeError: dst is not a numpy array, neither a scalar
1) I'm running opencv2 but is this code only for open cv3?
I go to this page to find out if individual lines are opencv 2 or 3, but it doesn't tell me.
2) If this code is for opencv3 is there something similar for opencv 2 or a good examples page for opencv2?
3) Is there any documentation that would enable me to check if individual lines of code are 2 or 3, because I don't want to debug code that will never work on my system, because I have the wrong version of opencv installed.
4) can I have opencv2 and 3 installed on my machine, or if I have opencv3 do I need opencv2 at all?
import cv2
import numpy as np
c = cv2.VideoCapture(0)
_,f = c.read()
avg1 = np.float32(f)
avg2 = np.float32(f)
while(1):
_,f = c.read()
cv2.accumulateWeighted(f,avg1,0.1)
cv2.accumulateWeighted(f,avg2,0.01)
res1 = cv2.convertScaleAbs(avg1)
res2 = cv2.convertScaleAbs(avg2)
cv2.imshow('img',f)
cv2.imshow('avg1',res1)
cv2.imshow('avg2',res2)
k = cv2.waitKey(20)
if k == 27:
break
Your code is perfectly OpenCV2.x matching, looking at the documentation of that function. I am guessing your are passing a mismatched parameter. For example, you are not reading any image at all for the moment, so that will return an empty parameter....
Got it on the documentation :), but I'm not sure how to check if I'm returning an empty parameter. I'm new to openCV, as you can tell!
could someone please explain
_,f = c.read()
what the comma is for? array?The underscore means that the function has 2 return values but you are not interested in the first.
I'm not sure what this means; could you please point me to a good example of this line of code, with a beginners explanation. Thanks :
return values are python style of programming... that is the basics...
Thanks, I've got it now.
I think this explains the underscore well, taken from half way downCamera.read() returns two values. A flag, and the image. The flag is Boolean as to wether an image is read or not. As he does not care about the flag he sets it to an underscore.
Like I said, returning values not being used :)