繁体   English   中英

找到最亮的轮廓opencv java

[英]Find the brightest contour opencv java

我试图用相机捕捉最明亮的区域。

我正在使用opencv和android studio(JAVA)。 到目前为止,关于Java的opencv资源和文档有限。

是一个新手程序员,因此任何建议都将有所帮助。

试图调试我的代码,但似乎无法超出代码的范围

Core.MinMaxLocResult max = minMaxLoc(wrapper);

有谁知道如何在JAVA中正确使用MinMaxLocResult函数?

还有一种更有效的方法来查找帧中最亮的区域吗?

我的代码`公共Mat onCameraFrame(CvCameraViewFrame inputFrame){

    Log.e(TAG, "on camera frame ");
    Mat mHierarchy = new Mat();
    mGrey = inputFrame.gray();
    mRgba = inputFrame.rgba();
    //find contour

Imgproc.findContours(mGrey,Mcontours,mHierarchy,Imgproc.RETR_EXTERNAL,Imgproc.CHAIN_APPROX_NONE);

    double maxMax=0;
    int num=0;

    for(int x = 0; x < Mcontours.size();x++){
        Mat wrapper = Mcontours.get(x);

        Core.MinMaxLocResult max = minMaxLoc(wrapper); **//error line**

        if(max.maxVal > maxMax){
            maxMax = max.maxVal;
            num = x;
        }
            if(x == Mcontours.size()){
                Imgproc.circle(mGrey,max.maxLoc,5,CONTOUR_COLOR);
                Imgproc.drawContours(mGrey,Mcontours,num,CONTOUR_COLOR);
            }

    }

返回mGrey}`

如果您想找到最大的轮廓,请查看我的代码:

mContours = new ArrayList<MatOfPoint>();
mObjectContours = new ArrayList<MatOfPoint>();

private void findObjectContour(Mat src) {
    mContours.clear();
    Imgproc.findContours(src, mContours, mHierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
    filterContoursArea(mContours);
}

private void filterContoursArea(List<MatOfPoint> mContours) {
    double maxArea = getMaxContourArea(mContours);
    mObjectContours.clear();

    for (int i = 0; i < mContours.size(); i++) {
        MatOfPoint contour = mContours.get(i);
        if (Imgproc.contourArea(contour) > mMinContourArea * maxArea) {
            mObjectContours.add(contour);
        }
    }
}

private double getMaxContourArea(List<MatOfPoint> contours) {
    double maxArea = 0;
    double area;
    for (int i = 0; i < contours.size(); i++) {
        area = Math.abs(Imgproc.contourArea(contours.get(i)));
        if (area > maxArea) {
            maxArea = area;
        }
    }
    return maxArea;
}

private int calculateMaxContourAreaIdx(List<MatOfPoint> contours) {
    double maxArea = 0;
    int maxHandContourAreaIdx = 0;
    double area;
    for (int i = 0; i < contours.size(); i++) {
        area = Math.abs(Imgproc.contourArea(contours.get(i)));
        if (area > maxArea) {
            maxArea = area;
            maxHandContourAreaIdx = i;
        }
    }
    return maxHandContourAreaIdx;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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