Ask Your Question

GongdoriCat's profile - activity

2017-08-30 08:38:57 -0500 received badge  Famous Question (source)
2015-12-16 05:03:43 -0500 received badge  Notable Question (source)
2015-06-29 23:06:58 -0500 received badge  Popular Question (source)
2013-10-09 16:45:36 -0500 asked a question (OpenCV4Android) How to use OpenCV camera in Service?

Hello, I'm currently developing an app which need to record video in background and process it.

(Control Android device using real-time image processing)

However, to achieve it, I need to use Camera and OpenCV as Service, and it seems that it is impossible to use JavaCamera and Android.Hardware.Camera without using any preview.

Here are my questions.

  1. I heard that NativeCamera can be used for this purpose. Is it possible? (Possibly with examples?)

  2. Is there any method that I can use JavaCameraView(or similar stuff) for this purpose? I currently use Galaxy S4.

Thank you for answering the question.

2013-09-14 14:57:08 -0500 asked a question Why this code causes memory leak?(Opencv4android)

Hi.

I'm currently learning about opencv4android, and I'm trying to create threshold image for use in color blob detection. However, the code shown here, do work for 5~10 minutes but crashes with

09-15 04:51:01.738: E/cv::error()(9066): OpenCV Error: Insufficient memory (Failed to allocate 3686404 bytes) in void* cv::OutOfMemoryError(std::size_t), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/alloc.cpp, line 52

Also, the error is always caused at cvtColor function in the code snippet(the image processing part) below.

The code had been tested for its stability in Python(not exactly, but kind of similar approach).

Thank you advance for answering this question.

    //Image Processing
    //Main Function
    public Mat processImage(Mat inputFrame){
        Mat inputFrame_HSV=new Mat();
        //initialize pointArray
        for(int i=0;i<6;i++){
            for(int j=0;j<2;j++)
                pointArray[i][j]=-1;
        }

        //Convert frame into HSV format(from RGB)
        Imgproc.cvtColor(inputFrame, inputFrame_HSV, Imgproc.COLOR_RGBA2RGB);
        inputFrame.release();
        Imgproc.cvtColor(inputFrame_HSV, inputFrame_HSV, Imgproc.COLOR_RGB2HSV);
        //Create threshold image
        Mat threshImage=getThresholdImg(inputFrame_HSV,HSV1,HSV2);
        inputFrame_HSV.release();

        return threshImage;
    }
    //Get Threshold Image
    public Mat getThresholdImg(Mat inputFrame_HSV,Scalar HSV1, Scalar HSV2){
        Mat threshImg=new Mat(inputFrame_HSV.size(),inputFrame_HSV.type());
        Core.inRange(inputFrame_HSV, HSV1, HSV2, threshImg);
        return threshImg;
    }
2013-09-14 13:32:32 -0500 commented question [OpenCV4Android] modifying frame(puttext, rectangle ... etc) not working on onCameraFrame

NOTE : I just discovered that i converted(I don't know why...) setCvCameraViewListener to comment(//). After reviving that line, it works very well. Ah! My precious 3 hours!

2013-09-14 12:13:28 -0500 received badge  Editor (source)
2013-09-14 12:09:27 -0500 asked a question [OpenCV4Android] modifying frame(puttext, rectangle ... etc) not working on onCameraFrame

Hello.

I'm a student who is trying to create a program which creates threshold image(using inrange, for use in color blob tracking)

However, I'm stuck with displaying the threshold image on JavaCameraView(for testing purposes).

According to other example and documentations, it seems that modifying OnCameraFrame(CvCameraViewFrame inputFrame)'s inputFrame.rgba() changes the displayed frame. However, I cannot see the modifications I made to the given frame(in the code below, it's mRgba in OnCameraFrame)

I tried to do the following

  1. input text overlay to the frame using puttext

  2. make the frame to be gray using Imgproc.cvtcolor

  3. tried to make thresholdimage using processImage(created inside the code)

None of them change the frame displayed.

I hope to see why the modifications don't work.

PS. The Phone I used was Galaxy S4 LTE-A SK Telecom (SHV-E330S) with OpenCV 2.4.6

PPS. Same thing happens in Nexus S with CM10

package com.example.opencvtrialexample;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.android.Utils;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.imgproc.Imgproc;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.Menu;
import android.view.SurfaceView;
import android.view.WindowManager;
import android.widget.ImageView;



public class MainActivity extends Activity implements CvCameraViewListener2{
    private static final String TAG="MyActivity_OpenCVTest";
    private CameraBridgeViewBase mOpenCvCameraView;
    private int[][] pointArray=new int[5][2];
    private final Scalar HSV1=new Scalar(20,100,100);
    private final Scalar HSV2=new Scalar(100,255,255);
    //OpenCV Initialization
    private BaseLoaderCallback mLoaderCallback=new BaseLoaderCallback(this){
        public void onManagerConnected(int status){
            switch(status){
                case LoaderCallbackInterface.SUCCESS:
                {
                    Log.i(TAG,"OpenCV loaded Successfully");
                    mOpenCvCameraView.enableView();
                }break;
                default:
                {
                    super.onManagerConnected(status);
                }break;
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.i(TAG,"called onCreate");
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        mOpenCvCameraView=(CameraBridgeViewBase)findViewById(R.id.HelloOpenCvView);
        mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);

        //mOpenCvCameraView.setCvCameraViewListener((CvCameraViewListener2) this);
    }
    public void onPause(){
        super.onPause();
        if(mOpenCvCameraView!=null)
            mOpenCvCameraView.disableView();

    }
    public void onDestroy(){
        super.onDestroy();
        if(mOpenCvCameraView!=null)
            mOpenCvCameraView.disableView();
    }
    public void onResume(){
        super.onResume();
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6,this,mLoaderCallback);
    }
    public void onCameraViewStarted(int width, int height){

    }
    public void onCameraViewStopped(){

    }
    public Mat onCameraFrame(CvCameraViewFrame inputFrame){//**This is where Problem Happens**
        Mat mRgba=inputFrame.rgba();
        Mat mProc=processImage(mRgba);
            //Not working puttext
        Core.putText(mRgba, "=====TEST=====2013.09.15", new Point(100, 500), 3, 1, new Scalar(255, 0, 0, 255), 2);
        //replacing mRgba with mProc
        Imgproc.cvtColor(mRgba, mRgba, Imgproc.COLOR_RGBA2GRAY);
        Imgproc.cvtColor(mRgba, mRgba, Imgproc.COLOR_GRAY2RGBA);
        //temporarily disabled to test whether puttext work
        //mProc.copyTo(mRgba);
        return mRgba;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is ...
(more)