android opencv画轮廓,Android OpenCV - 在轮廓上绘制矩形

此篇博客介绍了如何在Android OpenCV中将获取的List<contours>转换为Rect[]数组,以便于在轮廓上准确绘制矩形。作者分享了如何避免直接转换错误,并推荐使用boundingRect方法获取轮廓的外接矩形。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如何将List contours转换为Rect[] contoursArray,以便我可以使用Core.rectangle(mRgba, contoursArray[i].tl(), contoursArray[i].br(), (255,0,0,255), 3)在其上绘制矩形?Android OpenCV - 在轮廓上绘制矩形

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

mRgba = inputFrame.rgba();

mGray = inputFrame.gray();

//Touch screen to track by color and draw rectangle on it

if (mItem_select && Color_Select){

mDetector.process(mRgba);

List contours = mDetector.getContours();

Log.e(TAG, "Contours count: " + contours.size());

Imgproc.drawContours(mRgba, contours, - 1, Rectangle_Color);

//Draw rectangle on it

Rect[] contoursArray = contours.toArray(); //error:Type mismatch: cannot convert from Object[] to Rect[]

Core.rectangle(mRgba, contoursArray.tl(), contoursArray.br(), (255, 0, 0, 255), 3); //error:Cannot invoke tl() on the array type Rect[]、Cannot invoke br() on the array type Rect[]

Mat colorLabel = mRgba.submat(4, 68, 4, 68);

colorLabel.setTo(mBlobColorRgba);

Mat spectrumLabel = mRgba.submat(4, 4 + mSpectrum.rows(), 70, 70 + mSpectrum.cols());

mSpectrum.copyTo(spectrumLabel);

}

return mRgba;

}

2013-09-30

Tony

+0

啊,不要试图将积分转换为矩形,而不是从轮廓采取外接矩形框,并绘制矩形! http://docs.opencv.org/java/org/opencv/imgproc/Imgproc.html#boundingRect(org.opencv.core.MatOfPoint) –

+0

这可能有助于http://docs.opencv.org/doc/tutorials/ imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.html#边界,rects-圈 –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值