简体   繁体   中英

Opencv Java adjusting rectangle dimensions

I am working on licence plate detection in OpenCv, currently I can detect a licence plate Sample of detected licence plate

在此处输入图片说明

But the issue is the rectangle is too close to the licence plate characters, what I thought was I could just increase the dimensions by a given offset of which I did Sample of increased offset detection 在此处输入图片说明

But unfortunately my understanding of the Rect is different from how it works, unlike the circle where you have a single point where it's drawn from, the rectangle uses 2 points, of which after increasing the dimensions, if shifts to the right(At least that is what it seems), I need help on centering the rectangle on its original location after increasing the offset, here is the code am using to increase it's dimensions

    rect.height = (int) (rect.height * 1.1);
    rect.width = (int) (rect.width * 1.5);
    Imgproc.rectangle(originalFrame, rect.br(), rect.tl(), new Scalar(0,0,255), 2);

I don't have enough rep yet so images do not display automatically.

If you increase the right side's x coordinate by length, then you need to make all of the rectangle's coordinates go left length/2. The same applies to height.

rect.xCoord = rect.xCoord - ((rect.width * 1.1) - rect.width) / 2)

This goes before the first line of code you posted above. I'm not sure if this is how you access x coordinates in open cv (since I don't know it), so replace the x coord access with the actual one if this is wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM