opencv 2 or 3 debugging? [closed]

asked 2015-01-26 08:58:06 -0600

reggie gravatar image

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
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by StevenPuttemans
close date 2015-01-31 04:34:35.945985

Comments

1

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

StevenPuttemans gravatar imageStevenPuttemans ( 2015-01-26 09:11:33 -0600 )edit

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!

reggie gravatar imagereggie ( 2015-01-26 09:58:28 -0600 )edit

could someone please explain _,f = c.read() what the comma is for? array?

reggie gravatar imagereggie ( 2015-01-26 10:30:58 -0600 )edit

The underscore means that the function has 2 return values but you are not interested in the first.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-01-26 13:01:30 -0600 )edit

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 :

reggie gravatar imagereggie ( 2015-01-27 12:41:57 -0600 )edit
1

return values are python style of programming... that is the basics...

StevenPuttemans gravatar imageStevenPuttemans ( 2015-01-27 16:21:18 -0600 )edit
1

Thanks, I've got it now.

reggie gravatar imagereggie ( 2015-01-28 06:35:42 -0600 )edit
1

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.

reggie gravatar imagereggie ( 2015-01-31 04:06:01 -0600 )edit

Like I said, returning values not being used :)

StevenPuttemans gravatar imageStevenPuttemans ( 2015-01-31 04:34:25 -0600 )edit