本文介绍了opencv如何在java中绘制minAreaRect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从 minAreaRect 绘制旋转的矩形,但我在 python 中只找到了代码.
Hi I am trying to draw the rotated rect from minAreaRect but I find only code in python.
rect = cv2.minAreaRect(cnt)
box = cv2.cv.BoxPoints(rect)
box = np.int0(box)
cv2.drawContours(im,[box],0,(0,0,255),2)
如何在java中绘制它?
How to draw it in java?
推荐答案
我知道这个问题很老了,但最近我遇到了同样的问题,所以我决定在这里发布答案.
I know this question is old, but recently I had the same problem so I decided to post the answer here.
不幸的是,我在 Android 上使用的 OpenCV 版本没有支持 RotatedRect
作为参数的方法 rectangle
.所以我不得不即兴发挥.
Unfortunately, the OpenCV version I'm using on Android doesnt have the method rectangle
that support RotatedRect
as paramenter. So I had to improvise.
Point points[] = new Point[4];
rect.points(points);
for(int i=0; i<4; ++i){
Core.line(init, points[i], points[(i+1)%4], new Scalar(255,255,255));
}
这篇关于opencv如何在java中绘制minAreaRect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!