Ask Your Question

Revision history [back]

I can't seem to detect which colour LED turned on

public void onCameraViewStarted(int width, int height) { // TODO Auto-generated method stub mHSV = new Mat();

    mRGBa = new Mat(height, width, CvType.CV_8UC3);
    mMaskMatBlue = new Mat();
     mMaskMatRed = new Mat();
    mMaskMatYellow = new Mat();
    mMaskMatGreen = new Mat();
    mRGBb = new Mat();

}

@Override
public void onCameraViewStopped() {
    // TODO Auto-generated method stub
    mRGBa.release();
    mRGBb.release();
    mHSV.release();
    mMaskMatBlue.release();
    mMaskMatRed.release();
    mMaskMatYellow.release();
    mMaskMatGreen.release();
}

@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    // TODO Auto-generated method stub

    //get current frame
            //mFrame = inputFrame;
                mRGBa = inputFrame.rgba();
                // Convert the image to HSV
                //Mat mBgr = null;          
                DetectColour(mRGBa);

    return inputFrame.rgba();
}

public void DetectColour( Mat mRgba){

    if(mRgba != null)
    {
        Mat mRGBb = new Mat();

        Imgproc.cvtColor(mRgba, mRGBb, Imgproc.COLOR_BGR2RGB);
         Imgproc.cvtColor(mRGBb,mHSV , Imgproc.COLOR_RGB2HSV);

        Core.inRange(mHSV,mLowerBoundBlue,mupperBoundBlue, mMaskMatBlue);
        Core.inRange(mHSV,mLowerBoundYellow,mupperBoundYellow, mMaskMatYellow);
        Core.inRange(mHSV,mLowerBoundGreen,mupperBoundGreen, mMaskMatGreen);
        Core.inRange(mHSV,mLowerBoundRed,mupperBoundRed, mMaskMatRed);

    try{

        FileOutputStream fileout=openFileOutput("messageFile.txt", MODE_PRIVATE);
        OutputStreamWriter outputWriter=new OutputStreamWriter(fileout);

            if(mMaskMatBlue != null){
                outputWriter.write("We have blue color \n");
             }

            if(mMaskMatRed != null){
                outputWriter.write("We have red color \n");
             }

            outputWriter.close();

    }catch (Exception e) {
        e.printStackTrace();
    }

    }