0

I am new to OpenCV.

As I am trying to detect laser dot using this code. But there is no change in output.As I found that it's not detection laser. Kindly help me in fixing this issue. Here is my code

@Override
    public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
        Mat frameH;
        Mat frameV;
        Mat frameS;

        //static int a=1;
        List<Mat> mChannels= new ArrayList<>();

        Mat originalFrame=new Mat();
        Mat frame=new Mat();

        inputFrame.rgba().copyTo(originalFrame);
        inputFrame.rgba().copyTo(frame);

        mRgba = inputFrame.rgba();

        Imgproc.cvtColor(frame,frame, Imgproc.COLOR_RGB2HSV);

        mChannels.clear();
        Core.split(frame, mChannels); // Split channels: 0-H, 1-S, 2-V
        frameH = mChannels.get(0);
        frameS = mChannels.get(1);
        frameV = mChannels.get(2);

        // Apply a threshold to each component
        Imgproc.threshold(frameH, frameH, 155, 160, Imgproc.THRESH_BINARY);
        Imgproc.threshold(frameV, frameV, 250, 256, Imgproc.THRESH_BINARY);

        // Perform an AND operation
        Core.bitwise_and(frameH, frameV, frame);

        frameH.release();
        frameV.release();
        frameS.release();

        frame.release();

        return originalFrame; // This function must return
    }
  • Perhaps a `List` as the [documentation of `Core.split`](https://docs.opencv.org/java/2.4.2/org/opencv/core/Core.html#split(org.opencv.core.Mat,%20java.util.List)) seems to suggest? Although having written that code, you probably ought to know what you declared it as. – Dan Mašek Mar 30 '18 at 16:45
  • I copied this code from here https://stackoverflow.com/questions/26743809/opencv-android-track-laser-dot but confused. – Somia Waseem Mar 30 '18 at 17:17
  • I see. Unfortunately that's a fairly poor question, since it's missing [mcve] (and a good example why it's required). Anyway, a `List` of `Mat`s should do the trick. – Dan Mašek Mar 30 '18 at 17:37
  • can you please tell which class I should initialize orignalframe ? – Somia Waseem Apr 10 '18 at 08:16
  • Well, since I can't see the rest of the code, `originalFrame` appears to really just be a temporary variable, so you could just make it local to `onCameraFrame`. However, you may want to keep it persist in memory to reduce the number of allocations, in which case make it a member of the class that contains `onCameraFrame` and initialize it... I guess in the constructor? – Dan Mašek Apr 10 '18 at 13:27
  • my issue has been solved but now it's not detection laser. here is source code can you please tell me what should I do. – Somia Waseem Apr 10 '18 at 18:33
  • @DanMašek i have updated my code please check this. – Somia Waseem Apr 10 '18 at 18:40

0 Answers0