Ask Your Question
0

How to do horizontal projection in opencv using java?

asked 2019-01-24 19:43:14 -0600

Janrex gravatar image

I have a mat file that contains a binarized image and i would like to do a horizontal projection to that image to get the peaks of black pixel so I can get the locations of horizontal lines.

here is a sample image that I'm currently using: image description

I would like to get the positions of stafflines from this kind of image.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-01-25 01:53:23 -0600

berak gravatar image

have a look at the docs, please

Mat projected = new Mat();
// we need a larger result type for sums !
Core.reduce(input, projected, 1, Core.REDUCE_SUM, CvType.CV_32F);

then apply non maximum suppression to find the peaks (or rather, minimum, for black on white !)

edit flag offensive delete link more

Comments

1
sturkmen gravatar imagesturkmen ( 2019-01-25 05:16:23 -0600 )edit

hi! i tried this answer but its giving me this error: Exception in thread "main" java.lang.UnsupportedOperationException: Mat data type is not compatible: 5

Janrex gravatar imageJanrex ( 2019-01-26 04:37:39 -0600 )edit

@Janrex, do you understand, why the reduce() output has to be float (or int) for REDUCE_SUM ?

and the error probably comes from your NEXT step, which we cannot see here.

please update your question, and show, what you're trying.

berak gravatar imageberak ( 2019-01-26 04:51:45 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-01-24 19:43:14 -0600

Seen: 426 times

Last updated: Jan 25 '19