Opencv不同的颜色检测

时间:2016-12-05 04:57:22

标签: android opencv contour

我想检测红色和橙色的颜色对象检测。此代码仅用于显示对象的红色或仅显示对象的橙色。如何​​显示红色和橙色对象检测?

    Imgproc.cvtColor(mRgba , mHsv, Imgproc.COLOR_RGB2HSV);

    Scalar lowerThreshold = new Scalar (159, 135, 135); // Red color – lower hsv values
    Scalar upperThreshold = new Scalar (179, 255, 255); // Red color – higher hsv values

    Scalar lowerThreshold2 = new Scalar (5,50,50); // Orange color – lower hsv values
    Scalar upperThreshold2 = new Scalar (15, 255, 255); // Orange color – higher hsv values

    Core.inRange ( mHsv, lowerThreshold , upperThreshold, mMaskMat );
    Core.inRange ( mHsv, lowerThreshold2 , upperThreshold2, mMaskMat2 );
    Imgproc.dilate ( mMaskMat, mDilatedMat, new Mat() );
    Imgproc.dilate ( mMaskMat2, mDilatedMat, new Mat() );

    // contours
            List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
    Imgproc.findContours ( mDilatedMat, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE );

     for ( int contourIdx=0; contourIdx < contours.size(); contourIdx++ )
      {
         if (Imgproc.contourArea(contours.get(contourIdx)) > 1000) {

             Imgproc.drawContours ( mRgba, contours, contourIdx, new Scalar(0, 255, 0), 5);
         }
      }

0 个答案:

没有答案