Ask Your Question
0

Using cv reduce in Python

asked 2016-12-07 18:08:29 -0600

tamina gravatar image

I'm trying to use cv reduce to get the projection of an image onto the x and y axis.

I used:

x_sum = cv2.reduce(img, 0, cv2.cv.CV_REDUCE_SUM, cv2.CV_32S)

I get this error:

OpenCV Error: Unsupported format or combination of formats (Unsupported combination of input and output array formats) in reduce.

I can't find any more detailed documentation on how to use reduce in Python. Does anyone know where I've gone wrong?

Alternatively, is there another method I could use? calcHist() seems to only find the colour histogram of the image.

edit retag flag offensive close merge delete

Comments

what is 'img' ?

berak gravatar imageberak ( 2016-12-07 19:11:09 -0600 )edit

img is actually the edges of my original picture

  img = cv2.imread('test.jpg', 0)
  img = cv2.medianBlur(img, 39)
  img = cv2.Canny(img, 30, 40)
tamina gravatar imagetamina ( 2016-12-07 19:49:53 -0600 )edit

Try to use CV_32F or CV_64F instead of CV_32S

pi-null-mezon gravatar imagepi-null-mezon ( 2016-12-08 01:29:03 -0600 )edit

@pi-null-mezon I have tried these and keep getting the same error.

tamina gravatar imagetamina ( 2016-12-08 22:00:41 -0600 )edit

Do not know what to say... In C++ your code works for CV_32S, CV_32F and CV_64F and throws same error for CV_16U, CV_16S. Maybe something wrong with the 'x_sum', how you initialize it?

pi-null-mezon gravatar imagepi-null-mezon ( 2016-12-09 00:33:19 -0600 )edit

@pi-null-mezon I haven't initialized it. In Python there is normally no need to initialize. Should I initialize?

tamina gravatar imagetamina ( 2016-12-11 17:06:05 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-12-11 17:43:24 -0600

tamina gravatar image

updated 2016-12-11 17:49:02 -0600

I ended up updating my version of OpenCV to 3.1.0 because I heard there had been an update on the Python bindings to cv::reduce since 2.4.13.

I also changed the function call to include 'dtype=' which I think is needed for all the optional arguments

dst = cv2.reduce(img, 0, cv2.REDUCE_SUM, dtype=cv2.CV_32S)

I no longer get an error! :)

Notes

  • img = the edges of an image that I imported

  • dst did not need to be initialised

  • cv2.cv.CV_REDUCE_SUM changed to cv2.REDUCE_SUM somewhere between versions (I didn't see any documentation on this, I just got an error saying it was no longer there and I guessed the new name.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-12-07 18:08:29 -0600

Seen: 8,272 times

Last updated: Dec 11 '16