Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request to change the test code(or interface?) #14204

Open
tegusi opened this issue Mar 31, 2019 · 2 comments
Open

Request to change the test code(or interface?) #14204

tegusi opened this issue Mar 31, 2019 · 2 comments

Comments

@tegusi
Copy link

tegusi commented Mar 31, 2019

Hello! I just submitted a pr, and the robot reports errors on modules/python/test/test_facedetect.py*, as

Traceback (most recent call last):
File "/build/precommit_linux64/opencv/modules/python/test/test_facedetect.py", line 55, in test_facedetect
rects = detect(gray, cascade)
File "/build/precommit_linux64/opencv/modules/python/test/test_facedetect.py", line 18, in detect
rects[:,2:] += rects[:,:2]
TypeError: list indices must be integers or slices, not tuple

and the source file is

def detect(img, cascade):
rects = cascade.detectMultiScale(img, scaleFactor=1.275, minNeighbors=4, minSize=(30, 30),
flags=cv.CASCADE_SCALE_IMAGE)
if len(rects) == 0:
return []
rects[:,2:] += rects[:,:2]
return rects

Since the C++ version of this code provides vector, the python version should return LIST OF TUPLES instead of NUMPY 2D ARRAY as above, which satisfy the consistency of vector convertion between Python and C as well.

void CascadeClassifierImpl::detectMultiScale( InputArray _image, std::vector<Rect>& objects,
std::vector<int>& rejectLevels,
std::vector<double>& levelWeights,
double scaleFactor, int minNeighbors,
int /*flags*/, Size minObjectSize, Size maxObjectSize,
bool outputRejectLevels )

Which can be fixed by convert it to numpy array
rects = np.array(rects)

System information (version)
  • OpenCV => 4.1.0
  • Operating System / Platform => Ubuntu 16.04
  • Compiler => gcc 5.4.0
Detailed description
Steps to reproduce
@alalek
Copy link
Member

alalek commented Mar 31, 2019

should return LIST OF TUPLES

Tuples are almost not usable for future processing (including math-based), so we using np.array instead of tuples whenever possible.
So we don't asking users to do this: rects = np.array(rects)

@tegusi
Copy link
Author

tegusi commented Apr 1, 2019

However, the reverse conversion(numpy array to vector) doesn't work well(pyopencv_to). In this issue, after my final pr the original code still fails because of python binding:

terminate called after throwing an instance of 'cv::Exception' what(): OpenCV(4.1.0-pre) /home/tegusi/opencv-master/modules/core/src/copy.cpp:254: error: (-215:Assertion failed) channels() == CV_MAT_CN(dtype) in function 'copyTo'

corresponds to this:

Mat m;
pyopencv_to(obj, m, info);
m.copyTo(value);

I've tried my best to solve this problem but failed...I wonder if you know how to solve this problem :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants