Ask Your Question

sp_mic88's profile - activity

2020-10-21 15:25:17 -0600 received badge  Nice Question (source)
2017-07-18 01:35:18 -0600 received badge  Famous Question (source)
2016-10-18 07:44:21 -0600 received badge  Popular Question (source)
2015-09-04 13:19:56 -0600 received badge  Notable Question (source)
2014-11-05 09:19:18 -0600 asked a question Core.multiply not working in OpenCV4Android

I'm developing an Android application, using OpenCV4Android ver. 2.4.9. The application opens, using JavaCameraView, a video-stream and allows to apply various effects to this stream.

For example, I have created this Vignette Filter:

public static void getVignetteFilters(Mat frame){
    int num_rows = frame.rows();
    int num_cols = frame.cols();
    Mat first_filter = Imgproc.getGaussianKernel(num_cols, 300);
    Mat second_filter = Imgproc.getGaussianKernel(num_rows, 300);
    Mat first_filter_transposed = first_filter.t();
    Log.i(TAG, "First Filter Transposed: Rows = " + first_filter_transposed.rows() + " Cols = " + first_filter_transposed.cols());
    Log.i(TAG, "Second Filter: Rows = "+second_filter.rows()+" Cols = "+second_filter.cols());
    Mat third_filter = new Mat();
    Core.multiply(second_filter, first_filter_transposed, third_filter);
    Core.MinMaxLocResult minMaxLocResult = Core.minMaxLoc(third_filter);
    double maxVal = minMaxLocResult.maxVal;
    Mat fourth_filter = new Mat();
    Core.divide(maxVal, third_filter, fourth_filter);
    Core.multiply(frame, fourth_filter, frame);
}

But when I try to apply it to my stream, this operation fails, due to this exception:

CvException [org.opencv.core.CvException: cv::Exception: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/arithm.cpp:1287: error: (-209) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function void cv::arithm_op(cv::InputArray, cv::InputArray, cv::OutputArray, cv::InputArray, int, void (**)(const uchar*, size_t, const uchar*, size_t, uchar*, size_t, cv::Size, void*), bool, void*)
]
        at org.opencv.core.Core.multiply_2(Native Method)
        at org.opencv.core.Core.multiply(Core.java:5229)

But in the logcat I have verified that the two matrices that I pass to the Core.multiply method have the number of columns of the first equal to the number of rows of the second, so the multiplication should be possible between them.

11-04 20:55:43.444  21376-21603/[...]::OpenCVFilters﹕ First Filter Transposed: Rows = 1 Cols = 1920
11-04 20:55:43.444  21376-21603/[...]::OpenCVFilters﹕ Second Filter: Rows = 1080 Cols = 1

Any help would be appreciated.

2014-08-22 12:17:27 -0600 received badge  Popular Question (source)
2013-10-06 03:40:28 -0600 commented answer Neural Networks with CVANN_MLP

The problem doesn't change. Now, I'll try to create the network in a new project. Anyway, thanks for all this help!

2013-10-06 03:12:50 -0600 commented answer Neural Networks with CVANN_MLP

Ok, the number of iterations is: 2 and the predicted value is: -1.17204 with exactly the parameter's values of the code above (it should be wrong because I should have values in the range [-1,1]). The classes of training are -1 and 1 and the layers of the net are two, one of 59 inputs and one of 1 output.

2013-10-06 02:40:13 -0600 commented answer Neural Networks with CVANN_MLP

I tried to change the entire set of training images on which I have calculated the feature vector. I also changed the network so that it is formed of only two levels (input / output). Even in this case the network does not predict, returns the same value for each feature vector of test.

2013-10-05 04:30:33 -0600 commented answer Neural Networks with CVANN_MLP

Yes, but it gives me the same results for every sample.

2013-10-04 11:44:27 -0600 asked a question CvANN_MLP give for every sample the same result

I have created a neural network with CvANN_MLP class, working with Opencv libraries in the 2.4.6 version. My Cv_ANN mlp network is:

 Mat trainingData(NUMERO_ESEMPI_TOTALE, 59, CV_32FC1);  
Mat trainingClasses(NUMERO_ESEMPI_TOTALE, 1, CV_32FC1);

for(int i=0;i<NUMERO_ESEMPI_TOTALE;i++){
    for(int j=0;j<59;j++){
        trainingData.at<float>(i,j) = featureVect[i][j];
    }
}

for(int i=0;i<NUMERO_ESEMPI_TOTALE;i++){
    trainingClasses.at<float>(i,0) = featureVect[i][59];
}

Mat testData (NUMERO_ESEMPI_TEST , 59, CV_32FC1);
Mat testClasses (NUMERO_ESEMPI_TEST , 1, CV_32FC1);
for(int i=0;i<NUMERO_ESEMPI_TEST;i++){
    for(int j=0;j<59;j++){
        testData.at<float>(i,j) = featureVectTest[i][j];
    }
}

//0 bocca, 1 non bocca.
testClasses.at<float>(0,0) = 1;
testClasses.at<float>(1,0) = 0;
testClasses.at<float>(2,0) = 1;
testClasses.at<float>(3,0) = 1;
testClasses.at<float>(4,0) = 0;
testClasses.at<float>(5,0) = 1;
testClasses.at<float>(6,0) = 0;
testClasses.at<float>(7,0) = 1;
testClasses.at<float>(8,0) = 1;
testClasses.at<float>(9,0) = 0;
testClasses.at<float>(10,0) = 0;
testClasses.at<float>(11,0) = 1;
testClasses.at<float>(12,0) = 0;
testClasses.at<float>(13,0) = 0;
testClasses.at<float>(14,0) = 0;
testClasses.at<float>(15,0) = 0;
testClasses.at<float>(16,0) = 0;
testClasses.at<float>(17,0) = 0;
testClasses.at<float>(18,0) = 0;
testClasses.at<float>(19,0) = 1;
testClasses.at<float>(20,0) = 1;
testClasses.at<float>(21,0) = 0;
testClasses.at<float>(22,0) = 1;
testClasses.at<float>(23,0) = 0;
testClasses.at<float>(24,0) = 1;
testClasses.at<float>(25,0) = 0;
testClasses.at<float>(26,0) = 0;
testClasses.at<float>(27,0) = 1;
testClasses.at<float>(28,0) = 1;
testClasses.at<float>(29,0) = 1;    

Mat layers = Mat(3, 1, CV_32SC1);
layers.row(0) = Scalar(59);
layers.row(1) = Scalar(3);
layers.row(2) = Scalar(1);

CvANN_MLP mlp;
CvANN_MLP_TrainParams params;
CvTermCriteria criteria;
criteria.max_iter = 100;
criteria.epsilon = 0.0000001;
criteria.type = CV_TERMCRIT_ITER | CV_TERMCRIT_EPS;
params.train_method = CvANN_MLP_TrainParams :: BACKPROP;
params.bp_dw_scale = 0.05 ;
params.bp_moment_scale = 0.05 ;
params.term_crit = criteria ;
mlp.create(layers);
// train
mlp.train(trainingData,trainingClasses,Mat(),Mat(),params);

Mat response(1, 1, CV_32FC1);
Mat predicted(testClasses.rows, 1, CV_32F);
Mat pred(NUMERO_ESEMPI_TEST, 1, CV_32FC1);
Mat pred1(NUMERO_ESEMPI_TEST, 1, CV_32FC1);
for(int i = 0; i < testData . rows ; i++){
    Mat response(1, 1, CV_32FC1);
    Mat sample = testData.row(i);
    mlp.predict(sample,response);
    predicted.at<float>(i ,0) = response.at <float>(0,0);
    pred.at<float>(i,0)=predicted.at<float>(i ,0);
    pred1.at<float>(i,0)=predicted.at<float>(i ,0);
    file<<"Value Image "<<i<<": "<<predicted.at<float>(i ,0)<<"\n";
    //cout<<"Value Image "<<i<<": "<<predicted.at<float>(i ,0)<<endl;
}

The problem is that this network return me for every test sample the same result. I don't know why. My network takes as input a set of feature vector with 59 input values and 1 output value. Could you help me?

Thanks in advance.

2013-10-03 11:06:54 -0600 commented answer Neural Networks with CVANN_MLP

Yes, it has to be predout.data.fl[0]. But now, all the values are equal. Why? What's wrong in the code?

2013-10-02 13:30:43 -0600 asked a question Neural Networks with CVANN_MLP

I am programming in C++ with Visual Studio 2012 and Opencv 2.4.6. I have a set of training images for which I have calculated the feature vectors. These feature vectors should become the input of my neural network, realized with the class CvANN_MLP. Every feature vector is composed of 60 attributes, 59 are the "inputs" of the neural network, and the last is the "output", that can be only 1 or 0. I have realized this neural network:

CvANN_MLP machineBrain;

double td[NUMERO_ESEMPI_TOTALE][60]; 

CvMat* trainData = cvCreateMat(NUMERO_ESEMPI_TOTALE, 59, CV_32FC1); 

CvMat* trainClasses = cvCreateMat(NUMERO_ESEMPI_TOTALE, 1, CV_32FC1); 

CvMat* sampleWts = cvCreateMat(NUMERO_ESEMPI_TOTALE, 1, CV_32FC1); 
//The matrix representation of our ANN. We'll have four layers.
CvMat* neuralLayers = cvCreateMat(4, 1, CV_32SC1);
CvMat trainData1, trainClasses1, neuralLayers1, sampleWts1;

cvGetRows(trainData, &trainData1, 0, NUMERO_ESEMPI_TOTALE);
cvGetRows(trainClasses, &trainClasses1, 0, NUMERO_ESEMPI_TOTALE);
cvGetRows(trainClasses, &trainClasses1, 0, NUMERO_ESEMPI_TOTALE);
cvGetRows(sampleWts, &sampleWts1, 0, NUMERO_ESEMPI_TOTALE);
cvGetRows(neuralLayers, &neuralLayers1, 0, 4);



cvSet1D(&neuralLayers1, 0, cvScalar(59));
cvSet1D(&neuralLayers1, 1, cvScalar(3));
cvSet1D(&neuralLayers1, 2, cvScalar(3));
cvSet1D(&neuralLayers1, 3, cvScalar(1));



for(int i=0;i<NUMERO_ESEMPI_TOTALE;i++){
    for(int j=0;j<59;j++){
        td[i][j] = featureVect[i][j];
    }
    if(i<45){
        td[i][59] = 0; //è una bocca!
    }else{
        td[i][59] = 1; //non è una bocca!
    }
}

//Mettiamo insieme i training data
for (int i=0; i<NUMERO_ESEMPI_TOTALE; i++){
    //I 59 input 
    for(int j=0;j<59;j++){
        cvSetReal2D(&trainData1, i, 0, td[i][j]);
    }
    //Output
    cvSet1D(&trainClasses1, i, cvScalar(td[i][59]));
    //I pesi (vengono tutti settati a 1)
    cvSet1D(&sampleWts1, i, cvScalar(1));
}


machineBrain.create(neuralLayers);
cout<<"Rete creata"<<endl;

//Train it with our data.
machineBrain.train(trainData,trainClasses,sampleWts,0,CvANN_MLP_TrainParams(cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,100000,/*1.0*/0.01/*riprovare 0.01*/),CvANN_MLP_TrainParams::BACKPROP,0.001,0.05));
cout<<"Rete addestrata"<<endl;

 Mat pred(num_test_sample, 1, CV_32FC1);
Mat pred1(num_test_sample, 1, CV_32FC1);
for(int i=0;i<NUMERO_ESEMPI_TEST; i++){
    float _sample[59];
    CvMat sample = cvMat(1, 59, CV_32FC1, _sample);
    float _predout[1];
    CvMat predout = cvMat(1, 1, CV_32FC1, _predout);
    for(int j=0;j<59;j++){
        sample.data.fl[j] = featureVectTest[i][j];
    }
    machineBrain.predict(&sample, &predout);
    cout<<endl<<predout.data.fl[i]<<endl;//risultato predizione!
    pred.at<float>(i,0)=predout.data.fl[i];
    pred1.at<float>(i,0)=predout.data.fl[i];
    file<<"Value Image "<<i<<": "<<predout.data.fl[i]<<"\n";
}

The values that are returned are of this type:

 Value Image 0: 0.475639
 Value Image 1: 0
 Value Image 2: 4.2039e-044
 Value Image 3: 1.4013e-045
 Value Image 4: -7.88636e-016
 Value Image 5: 1.31722e-043
 Value Image 6: 4.2039e-044
 Value Image 7: 1.4013e-045
 Value Image 8: 0.0154511
 Value Image 9: 0.00100189
 Value Image 10: 0.00161414
 Value Image 11: 0.0449422
 Value Image 12: 7.5433
 Value Image 13: 65.8052
 Value Image 14: 24.301
 Value Image 15: 19.7311
 Value Image 16: 0.985553
 Value Image 17: 0.965309
 Value Image 18: 0.971295

So I haven't results of 0 ... (more)

2013-09-28 10:13:24 -0600 asked a question Pass an array of Mats to native code

How can I write my c++ JNI function so that it returns an array of Mat to Java code? I am programming in Android environment, with the help of NDK to use also some functions of OpenCV.

My c++ function is:

 JNIEXPORT void JNICALL Java_com_micaela_myapp_MainActivity2_getFrames(JNIEnv* env, jobject object, jstring path)
{
    const char *str;
    str = env->GetStringUTFChars(path, NULL);   
    VideoCapture input_video;
    if(input_video.open(str)){
        cout<<"Video File Opened"<<endl;
    }else{
        cout<<"Video File Not Found"<<endl;
    }
    Mat image;
    Mat frameBuffer[1000];  
    int i=0;
    while(input_video.read(image)==true){
        image.copyTo(frameBuffer[i]);
        i++;
    }
}

In Java I have:

static{
    System.loadLibrary("myapp");
}
public static native void getFrames(String path);

This function now returns void and works properly. However, my purpose is to obtain the array frameBuffer from it, in order to use it in Java. How can I do this?

2013-09-15 09:19:45 -0600 commented answer split function throws exception

I've followed exactly that guide to install opencv on vs 2012. So I'll try to install the new version of the libraries.

2013-09-15 04:26:22 -0600 asked a question split function throws exception

I am using the OpenCV libraries, in 2.4.6 version, with Visual Studio 2012. In my program, I simply read an image into a Mat, and then split it in the three mat, one for every single channel (B, G, R). The 'split' instruction throws an unhandled exception, that I am not able to manage. My program is simply:

 int main( int argc, const char** argv ){
      Mat image1;
      image1 = imread("i014sd-fn.jpg", CV_LOAD_IMAGE_COLOR);   
      if(!image1.data){
         cout << "Impossibile aprire l'immagine 1!"<<std::endl ; 
         return -1;
      }
      Mat image1gray;
      cvtColor(image1, image1gray, CV_BGR2GRAY);
      vector<Mat> bgr_planes;
      split(image1,bgr_planes);
      waitKey(0);                                      
      return 0;
  }

The Debug Window shows me this output:

 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\Users\Micaela\Documents\Visual Studio 2012\Projects\ConsoleApplication2\x64\Release\ConsoleApplication2.exe' completato. Simboli caricati.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\Windows\System32\ntdll.dll' completato. Impossibile trovare o aprire il file PDB.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\Windows\System32\kernel32.dll' completato. Impossibile trovare o aprire il file PDB.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\Windows\System32\KernelBase.dll' completato. Impossibile trovare o aprire il file PDB.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\OpenCV-2.4.6\opencv\build\x64\vc10\bin\opencv_core246.dll' completato. Impossibile trovare o aprire il file PDB.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\OpenCV-2.4.6\opencv\build\x64\vc10\bin\opencv_highgui246.dll' completato. Impossibile trovare o aprire il file PDB.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\OpenCV-2.4.6\opencv\build\x64\vc10\bin\opencv_imgproc246.dll' completato. Impossibile trovare o aprire il file PDB.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\Windows\System32\msvcp110.dll' completato. Simboli caricati.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\Windows\System32\msvcr110.dll' completato. Simboli caricati.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\Windows\System32\msvcp100.dll' completato. Impossibile trovare o aprire il file PDB.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\Windows\System32\msvcr100.dll' completato. Impossibile trovare o aprire il file PDB.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\Windows\System32\user32.dll' completato. Impossibile trovare o aprire il file PDB.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\Windows\System32\gdi32.dll' completato. Impossibile trovare o aprire il file PDB.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\Windows\System32\ole32.dll' completato. Impossibile trovare o aprire il file PDB.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\Windows\System32\oleaut32.dll' completato. Impossibile trovare o aprire il file PDB.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\Windows\System32\advapi32.dll' completato. Impossibile trovare o aprire il file PDB.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\Windows\System32\comctl32.dll' completato. Impossibile trovare o aprire il file PDB.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\Windows\System32\avifil32.dll' completato. Impossibile trovare o aprire il file PDB.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\Windows\System32\msvfw32.dll' completato. Impossibile trovare o aprire il file PDB.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\Windows\System32\avicap32.dll' completato. Impossibile trovare o aprire il file PDB.
 'ConsoleApplication2.exe' (Win32): caricamento di 'C:\Windows\System32\combase.dll' completato. Impossibile trovare o aprire il file PDB.
 'ConsoleApplication2 ...
(more)
2013-09-13 04:20:51 -0600 asked a question WSD descriptor in opencv

Do the opencv libraries contain functions to subject a grayscale image to an L-level discrete wavelet decomposition? I want to calculate the three detail images HL, LH and HH for every level, in order to use them to obtain the weighted standard deviation decriptor (WSD).

2013-09-11 10:32:11 -0600 commented answer Further image processing analysis on roi

I have already identified the face, and within it the regions of eyes, nose and mouth. For this purpose, I have used cascade classifiers of opencv. The problem is that the mouth classifier returns a lot of false positive. So, my purpose was to find a way to analyze the ROI of mouth, to check if it really contains a mouth. So, for example, I can think to study the color of image, because red pixel are probably pixel of mouth. I can also study the texture of mouth.

2013-09-11 02:38:02 -0600 commented answer Further image processing analysis on roi

So do you suggest me to use another classifier? Because I have already trained one, and this returns me that set of roi. My goal was to study these without other classifiers, but analysing with the help of texture or color information (it's only an idea).

2013-09-11 01:27:53 -0600 asked a question Further image processing analysis on roi

I have a question to ask: suppose you have a classifier that locate the mouth within the face in an image, this classifier returns multiple ROI as a result. I would like to do further analysis on each of these roi, to determine if, within these, there really is a mouth or not. How could I make this kind of analysis? What are the techniques of image processing to use? I would be grateful if you could recommend some article, or link me the material that may still be useful to me.

2013-09-11 01:20:59 -0600 commented question Camera Orientation in Android App

Yes, I've used the flip method, in this way: if (rot == 270) { // Rotate clockwise 270 degrees Core.flip(mat.t(), mat, 0); } else if (rot == 180) { // Rotate clockwise 180 degrees Core.flip(mat, mat, -1); } else if (rot == 90) { // Rotate clockwise 90 degrees Core.flip(mat.t(), mat, 1); } See here for more details: http://www.technolabsz.com/2012/08/how-to-flip-image-in-opencv.html

2013-07-30 08:37:21 -0600 asked a question MatchTemplate exception in android-opencv

I am developing an Android application, using Opencv libraries (version 2.4.5). The application simply opens a video stream and captures frames from it. Every frame is processed with image-processing techniques in order to detect faces and, within them, features (fiducial points).

I use, for eyes, the matchTemplate method, and sometimes, I have this error:

 07-30 11:26:44.355: ERROR/AndroidRuntime(23441): FATAL EXCEPTION: Thread-10570
    CvException [org.opencv.core.CvException: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/imgproc/src/templmatch.cpp:70: error: (-215) corrsize.height <= img.rows + templ.rows - 1 && corrsize.width <= img.cols + templ.cols - 1 in function void cv::crossCorr(const cv::Mat&, const cv::Mat&, cv::Mat&, cv::Size, int, cv::Point, double, int)
    ]
    at org.opencv.imgproc.Imgproc.matchTemplate_0(Native Method)
    at org.opencv.imgproc.Imgproc.matchTemplate(Imgproc.java:7226)
    at com.micaela.myapp.Eye.match(Eye.java:265)
    at com.micaela.myapp.Eye.access$100(Eye.java:22)
    at com.micaela.myapp.Eye$4.run(Eye.java:172)
    at java.lang.Thread.run(Thread.java:856)

I don't understand what is corrsize. The piece of code that throws this exception is:

  Mat res;
  if ((roi.height() > MainActivity.tpl.height()) && (roi.width() > MainActivity.tpl.width())) {
        res = new Mat(new Size(roi.cols() - MainActivity.tpl.cols() + 1, roi.rows() - MainActivity.tpl.rows() + 1), CvType.CV_32FC1);
       if((roi.depth() == CvType.CV_8U || roi.depth() == CvType.CV_32F) && roi.type() == MainActivity.tpl.type()) { //altra eccezione che veniva lanciata!
                Imgproc.matchTemplate(roi, MainActivity.tpl, res, Imgproc.TM_SQDIFF);
                if (left) {
                    return new Point((eyeRect.x + this.roi.width() - matchRect.x - Math.round(Core.minMaxLoc(res).maxLoc.x + (MainActivity.tpl.width() / 2))),
                            (Math.round(Core.minMaxLoc(res).maxLoc.y + (MainActivity.tpl.height() / 2)) + matchRect.y + eyeRect.y));
                } else {
                    return new Point((Math.round(Core.minMaxLoc(res).maxLoc.x + (MainActivity.tpl.width() / 2)) + matchRect.x + eyeRect.x), (Math.round(Core.minMaxLoc(res).maxLoc.y + (MainActivity.tpl.height() / 2)) + matchRect.y + eyeRect.y));
                }
            }
        }
2013-07-09 12:37:57 -0600 received badge  Student (source)
2013-06-06 08:02:53 -0600 received badge  Editor (source)
2013-06-06 06:46:42 -0600 commented answer Transposing and Flipping Frames on Android Camera

ok, thank you!

2013-06-06 06:46:13 -0600 received badge  Scholar (source)
2013-06-06 06:43:07 -0600 asked a question Splitting cameracontrol sample in two threads

Good morning to all. I have imported into Eclipse Juno the sample of OpenCv4Android, ver. 2.4.5, called "cameracontrol". It can be found here:Camera Control OpenCv4Android Sample.

Now I want to use this project as base for mine. I want to process every frame with image-processing techniques, so, in order to improve performance, I want to split the main activity of the project in two classes: one that is merely the activity and one (a thread) that is responsible for preview.

How can I do? Are there any examples about this?

2013-05-31 04:43:56 -0600 asked a question Android Preview Camera doesn't fill its FrameLayout

Good morning to all. I have started to study something of Android, in order to develop some applications. For this purpose, I use Eclipse Juno. Then, I have also downloaded Opencv4Android (in the 2.4.5 version), to use functionalities of these libraries. I have imported all the tutorials in Eclipse, and I have decided to use the sample "cameracontrol" as base for my app. Now, I have a problem: I have located the preview of camera within a frame layout at the top of the interface. But the frame layout appears in this way: there are black borders around the camera preview because the preview size is different from that of frame layout, so they don't match.

In camera control, in the class Tutorial3View, there's a function that allows the change of the resolution of the preview, so it should be possible to adapt this to the size of frame layout, but if I insert in the onCreate() method of the main activity, the app crashes. The method is:

public void setResolution(Size resolution) {
    disconnectCamera();
    mMaxHeight = resolution.height;
    mMaxWidth = resolution.width;
    connectCamera(getWidth(), getHeight());
}

So if in OnCreate() method I try to obtain frame layout width and height, to pass this as Size to setResolution, my code doesn't work.

Otherwise, I'd prefer to adapt the size of frame layout to that of preview, in order not to have distortion in the preview.

This is the xml code of the frame layout:

<FrameLayout
    android:id="@+id/frame_capture"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:visibility="visible"
    android:clickable="false" android:foregroundGravity="fill"      android:layout_weight="0.7"
    android:layout_gravity="top">
    <com.micaela.myapp.MyView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/HelloOpenCvView"
            android:visibility="gone"
            opencv:show_fps="true"
        />
    <ImageButton
            android:layout_width="51dp"
            android:layout_height="43dp"
            android:id="@+id/imageButton"
            android:layout_gravity="bottom|left"
            android:src="@drawable/switch_cam"
            android:background="#FF000000" android:cropToPadding="false" android:scaleType="centerCrop"/>
 </FrameLayout>

The tutorial I have used is
this

and this tutorial uses the class org.opencv.android.JavaCameraView to open the camera of device. How can I do? Any help would be very appreciated.

I have also thought to adapt the size of every single frame on the fly, when it's captured. So in the method onCameraFrame, I call this function:

public void manageSize(Mat matrix){
    size = new org.opencv.core.Size(frameLayout.getMeasuredWidth(),frameLayout.getMeasuredHeight());
    Log.i(TAG,"ciao "+frameLayout.getMeasuredHeight());
    Log.i(TAG,"ciao "+frameLayout.getMeasuredWidth());
    Log.i(TAG,"prova "+size); 
    Imgproc.resize(matrix,matrix,size);
}

passing the frame and where frameLayout is the container of the preview. I have verified that values of width and height of the frame arrive correctly. In this case, I get this error:

05-31 11:34:47.548: ERROR/cv::error()(17253): OpenCV Error: Assertion failed (src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols) in void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean), file /home/reports/ci/slave/50-SDK/opencv/modules/java/generator/src/cpp/utils ...
(more)
2013-05-28 08:12:47 -0600 asked a question How to save preview frames into a buffer

I have created a simple Android application that uses OpenCV4Android to open a video stream and capture frames from it. I have extended the class org.opencv.android.JavaCameraView and, in order to capture frames, this object offers the method onCameraFrame(CvCameraViewFrame inputFrame). If I want to save these frames into a buffer, so with a separate process I can process some of them, how can I do? Which objects should I use to create this buffer?

2013-05-24 05:13:44 -0600 asked a question Transposing and Flipping Frames on Android Camera

Good morning. I am using Opencv4Android, ver 2.4.5, with Eclipse Juno. I have imported the opencv tutorial into Eclipse, and I have realized that face-detection sample, camera-control sample, ect, work only in landscape mode. I want to use these projects as base for my application, so I want to make possible to use that applications in all rotations of a device. So, I have found that it's possible to transpose and flip on the fly captured frames, in this way:

@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    mRgba = inputFrame.rgba();
    mGray = inputFrame.gray();  

    Display display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int screenOrientation = display.getRotation();
    switch (screenOrientation){
        default:
        case ORIENTATION_0: // Portrait
            Core.flip(mRgba.t(), mRgba, 1);
            break;
        case ORIENTATION_90: // Landscape right
            // do smth.
            break;
        case ORIENTATION_270: // Landscape left
            // do smth.
            break;
    }
    return mRgba;
}

But the only result is that, in portrait mode, now the camera is only a black screen. The error in the logcat is:

05-24 12:05:55.168: ERROR/cv::error()(15219): OpenCV Error: Assertion failed (src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols) in void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean), file /home/reports/ci/slave/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp, line 97
05-24 12:05:55.168: ERROR/org.opencv.android.Utils(15219): nMatToBitmap catched cv::Exception: /home/reports/ci/slave/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)
05-24 12:05:55.168: ERROR/CameraBridge(15219): Mat type: Mat [ 720*480*CV_8UC4, isCont=true, isSubmat=false, nativeObj=0x40e1f018, dataAddr=0x774c6010 ]
05-24 12:05:55.168: ERROR/CameraBridge(15219): Bitmap type: 720*480
05-24 12:05:55.168: ERROR/CameraBridge(15219): Utils.matToBitmap() throws an exception: /home/reports/ci/slave/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)

Please help me, if possible.

2013-05-23 03:14:46 -0600 asked a question Camera Orientation in Android App

Good morning to all. I have created an Android app that opens a video stream, extending the class JavaCameraView. The application should capture frames to process them. I have used, to realize this app, the tutorials contained in the OpenCV4Android package (version 2.4.5). I use Eclipse Juno, and my phone is a samsung s4, and surfing the web I realize that my problem is very common on many devices, including galaxy s,s2,s3,s4. My problem is that my camera, when is opened, in portrait mode results rotated of 90 degrees. It seems to be always in landscape orientation. I have read somewhere that it is possible to flip camera on the fly, but I have not understood how. Could someone help me?

2013-05-21 10:36:16 -0600 asked a question How to add a button to switch between cameras

How can I add a button to camera-control opencv4android example? I have simply added in the main.xml file:

<button android:id="@+id/imgShoot" android:text="Capture" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|right"/> and in OnCreate function, in MainActivity.java, after setContentView:

final Button button = (Button) findViewById(R.id.button_id); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click } }); but it doesn't work. This button should be able to switch between front and back camera, in my device.

2013-05-21 10:34:49 -0600 asked a question Wrong orientation of JavaCameraView

I have developed an Android app that, using opencv libraries, opens a video stream and captures frames from it. The problem is that the orientation of the application is portrait, and this allows me to see correctly the menu of the app, but camera is badly rotated (90 degrees to the correct orientation). I use JavaCameraView to open my camera. How can I do?

The problem is that the method: setCameraDisplayOrientation(Activity activity, int cameraId) doesn't work, and the call: this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) rotates correctly camera but rotates also the menu that becomes badly rotated itself.
This probably because I don't use classes Camera and SurfaceView, but I access the camera through opencv, using the org.opencv.JavaCameraView.

2013-05-18 08:00:50 -0600 asked a question NativeCameraView in OpenCV4Android not working

Good morning to all. I have tried to create a simple application for Android that uses opencv4android. This app simply should access through opencv to camera, and captures frames. I have followed this guide: http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html#application-development-with-async-initialization If I use org.opencv.android.JavaCameraView it works correctly, but if I want to use org.opencv.NativeCameraView, when I try to run the app, in my logcat I see:

 05-18 13:00:16.979: E/OpenCV::camera(29894): ||libnative_camera_r2.3.3.so
 05-18 13:00:16.979: E/OpenCV::camera(29894): ||libnative_camera_r4.0.3.so
 05-18 13:00:16.979: E/OpenCV::camera(29894): ||libnative_camera_r4.2.0.so
 05-18 13:00:16.979: E/OpenCV::camera(29894): ||libnative_camera_r4.1.1.so
 05-18 13:00:16.979: E/OpenCV::camera(29894): ||libnative_camera_r4.0.0.so
 05-18 13:00:16.979: E/OpenCV::camera(29894): ||libnative_camera_r2.2.0.so
 05-18 13:00:16.979: E/OpenCV::camera(29894): ||libnative_camera_r3.0.1.so
 05-18 13:00:17.239: A/libc(29894): @@@ ABORTING: LIBC: HEAP MEMORY CORRUPTION IN dlmalloc
 05-18 13:00:17.249: A/libc(29894): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 29894 (.videocamopencv)

Here my code:

---MAIN ACTIVITY:

package com.example.videocamopencv;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.NativeCameraView;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Mat;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.SurfaceView;
import android.view.WindowManager;

public class MainActivity extends Activity implements CvCameraViewListener2{
private NativeCameraView mOpenCvCameraView;
private static final String TAG ="VideoCamera App :: ";

private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status) {
        switch (status) {
            case LoaderCallbackInterface.SUCCESS:
            {
                Log.i(TAG, "OpenCV loaded successfully");
                mOpenCvCameraView.enableView();
            } break;
            default:
            {
                super.onManagerConnected(status);
            } break;
        }
    }
};

public MainActivity(){
    Log.i(TAG, "Instantiated new " + this.getClass());
}

@Override
public void onResume()
{
    super.onResume();
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "called onCreate");
     super.onCreate(savedInstanceState);
     getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
     setContentView(R.layout.activity_main);
     mOpenCvCameraView = (NativeCameraView) findViewById(R.id.HelloOpenCvView);
     mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
     mOpenCvCameraView.setCvCameraViewListener(this);

}

@Override
 public void onPause()
 {
     super.onPause();
     if (mOpenCvCameraView != null)
         mOpenCvCameraView.disableView();
 }

 public void onDestroy() {
     super.onDestroy();
     if (mOpenCvCameraView != null)
         mOpenCvCameraView.disableView();
 }

 public void onCameraViewStarted(int width, int height) {
 }

 public void onCameraViewStopped() {
 }

 @Override
 public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
     return inputFrame.rgba();
 }

}

----MANIFEST.XML:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.videocamopencv"
android:versionCode="21"
android:versionName="2.1" >


<!-- android:icon="@drawable/ic_launcher" -->
<!-- android:label="@string/app_name" -->
<!-- android:theme="@style/AppTheme" -->
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
    <activity
        android:name="MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        android:configChanges="keyboardHidden|orientation" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent ...
(more)