Python bindings export `sum` which returns 4-tuples (Bug #902)


Added by Sergey Astanin about 14 years ago. Updated over 13 years ago.


Status:Done Start date:
Priority:Low Due date:
Assignee:- % Done:

0%

Category:python bindings
Target version:-
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

The sum function exported by python bindings returns unexpected results which are not documented. Potential conflicts with the code which uses numpy/scipy.

cv.sum returns 4-tuples, where the first item is the sum of the numpy array, and the remaining three seem to be zeros (I didn't observe other values).

Example (from ipython shell):

import numpy, cv; x=numpy.arange(10) ; sum(x) ; numpy.sum(x) ; cv.sum(x)

45
45
(45.0, 0.0, 0.0, 0.0)

numpy.+version+ ; cv.+version+ ;

'1.5.0'
'$Rev: 3057 $'

!uname -srom

Linux 2.6.34-020634-generic x86_64 GNU/Linux

cv.sum.+doc+

'sum(src) -> retval'

This is confusing, because

1. existance of cv.sum is not document and it doesn't 
follow the naming conventions of [[OpenCV]], so the user
doesn't expect that if sum suddenly works wrong,
it is [[OpenCV]] import which may be responsible;
2. this behavior is inconsistent with the behavior of numpy's
and builtin sum@s and breaks a lot of code;
3. this result of @cv.sum
is not documented; the docstring
of cv.sum tells only: "sum(src) -> retval". The semantics
of the returned tuple is not explained.

This is also a reason why from cv import * cannot be used even in small quick and dirty scripts which happen to use also numpy or scipy. Other forms (import cv; from cv import Foo, Bar, Baz, ...) require a lot of additional typing (redundant cv. prefix to all constansts, like cv.CV_32F, and function names, or very long explicit import lists).

Other potentially problematic functions in cv module, which share common names with numpy functions, are: add, bitwise_and, bitwise_not, bitwise_or, bitwise_xor, divide, exp, invert, log, max, mean, min, multiply, repeat, resize, sort, split, sqrt, subtract, sum, trace, transpose

I suggest

  • either do not export these lower-case functions from cv
  • or document their behavior and move them in a separate package
  • or make them compatible with numpy functions

Associated revisions

Revision 30020a73
Added by Vadim Pisarevsky over 13 years ago

renamed sum() to sumElems() in Python/Java bindings (ticket #902)

Revision d4255b7f
Added by Andrey Pavlenko almost 12 years ago

Merge pull request #902 from apavlenko:fix_run_py

Revision 5ac3b8d5
Added by Roman Donchenko almost 12 years ago

Merge remote-tracking branch 'origin/2.4' into merge-2.4

Pull requests:
#904 from ograycode:2.4
#905 from bitwangyaoyao:2.4_TVL1
#902 from apavlenko:fix_run_py
#882 from pengx17:2.4_rewrite_query_info

Conflicts:
modules/nonfree/src/surf.ocl.cpp
modules/ocl/include/opencv2/ocl/private/util.hpp
modules/ocl/src/hog.cpp
modules/ocl/src/pyrlk.cpp
modules/ocl/src/tvl1flow.cpp

History

Updated by Vadim Pisarevsky over 13 years ago

fixed in r5454

  • Status changed from Open to Done
  • (deleted custom field) set to fixed

Also available in: Atom PDF