2011-06-28 20 views
6

Estoy tratando de implementar el flujo óptico en Android usando openCV http://code.google.com/p/android-opencv/. Básicamente quiero construir algo como esto http://www.youtube.com/watch?v=P_Sjn67jIJY. De todos modos, porque soy nuevo en el desarrollo de Android, ¿alguien puede guiarme en algún lugar para construir algo como el del video? Ya instalé el puerto opencv en android y construí el ejemplo de cvcamera exitosamente usando eclipse. Gracias, ThanosAndroid Flujo óptico con opencv

Respuesta

1

Vea este flujo óptico OpenCV de Stanford link. Las cosas deberían funcionar básicamente de la misma manera, excepto que las llamadas pueden ser ligeramente diferentes debido a los problemas de API de C contra C++ de 1.x contra 2.x.

Simplemente edite el ejemplo CVCamera y debería ser rápido. Hice una aplicación de detección de rostros en tiempo real en aproximadamente una hora para que CVCamera funcione.

+0

Ya he encontrado eso, pero mi falta de conocimiento en java no me deja hacer que se ejecute para android .. = \ – thanos

+0

Ese es el primer paso. Pensé que ya creabas el ejemplo de CVCamera de la fuente y lo instalaste. Tenga en cuenta que esto es muy diferente de simplemente descargar el .apk y jugar con él. – peakxu

+0

Ya he compilado la CVCamera usando cygwin bash shell y la he abierto con eclipse sin ningún error. También cambié la resolución para correr más rápido la detección de características que la CVCamera tiene – thanos

0

Visita http://opencv.willowgarage.com/wiki/Android2.3.0, OpenCV 2.3.0 Release Candidate tiene un buen soporte para Android. Hay flujo óptico dentro de él ... lo usé

+0

¡Gracias por su ayuda! ¿Dónde está exactamente la muestra de flujo óptico en el opencv 2.3.0? Ya lo descargué y tan pronto como busqué no pude encontrar ninguna implementación de flujo óptico, solo encontré cómo detectar características con FAST, SURF Y STAR en la CVCamera ... – thanos

+0

que son las muestras ¿no? necesita escribir su propio uso (cv :: calcOpticalFlowPyrLK) y compilar de nuevo con NDK [http://opencv.willowgarage.com/wiki/OpenCVAndroidBinariesBuild] – shernshiou

+0

, por otro lado, puede seguir https://groups.google. com/group/android-opencv/browse_thread/thread/c0c011cb8e7f3e0C#, supongo que este chico construyó con éxito una aplicación de flujo óptico – shernshiou

1

Aunque también estoy tratando de hacer lo mismo, ahora parece haber más soporte para el flujo óptico en OpenCV4Android. Mire las API en org.opencv.video OpenCV Java documentation Veo calcOpticalFlowPyrLK y calcOpticalFlowFarneback. Pude hacer funcionar calcOpticalFlowFarneback (aunque los resultados no parecían tan buenos, posiblemente haya que modificar los parámetros) calcOpticalFlowPyrLK está demostrando ser complicado. Parece que no puedo convertir los puntos clave devueltos por la clase FeatureDetector (MatOfKeyPoint) a los puntos necesarios por calcOpticalFlowFarneback (MatOfPoint2f) other thread

0

Este código lo ayudará a obtener los vectores ópticos. Y se hará un seguimiento de ellas

@ Override pública Mat onCameraFrame (CvCameraViewFrame inputFrame) {

mRgba = inputFrame.rgba(); 
    if (mMOP2fptsPrev.rows() == 0) { 

     //Log.d("Baz", "First time opflow"); 
     // first time through the loop so we need prev and this mats 
     // plus prev points 
     // get this mat 
     Imgproc.cvtColor(mRgba, matOpFlowThis, Imgproc.COLOR_RGBA2GRAY); 

     // copy that to prev mat 
     matOpFlowThis.copyTo(matOpFlowPrev); 

     // get prev corners 
     Imgproc.goodFeaturesToTrack(matOpFlowPrev, MOPcorners, iGFFTMax, 0.05, 20); 
     mMOP2fptsPrev.fromArray(MOPcorners.toArray()); 

     // get safe copy of this corners 
     mMOP2fptsPrev.copyTo(mMOP2fptsSafe); 
     } 
    else 
     { 
     //Log.d("Baz", "Opflow"); 
     // we've been through before so 
     // this mat is valid. Copy it to prev mat 
     matOpFlowThis.copyTo(matOpFlowPrev); 

     // get this mat 
     Imgproc.cvtColor(mRgba, matOpFlowThis, Imgproc.COLOR_RGBA2GRAY); 

     // get the corners for this mat 
     Imgproc.goodFeaturesToTrack(matOpFlowThis, MOPcorners, iGFFTMax, 0.05, 20); 
     mMOP2fptsThis.fromArray(MOPcorners.toArray()); 

     // retrieve the corners from the prev mat 
     // (saves calculating them again) 
     mMOP2fptsSafe.copyTo(mMOP2fptsPrev); 

     // and save this corners for next time through 

     mMOP2fptsThis.copyTo(mMOP2fptsSafe); 
     } 


    /* 
    Parameters: 
     prevImg first 8-bit input image 
     nextImg second input image 
     prevPts vector of 2D points for which the flow needs to be found; point coordinates must be single-precision floating-point numbers. 
     nextPts output vector of 2D points (with single-precision floating-point coordinates) containing the calculated new positions of input features in the second image; when OPTFLOW_USE_INITIAL_FLOW flag is passed, the vector must have the same size as in the input. 
     status output status vector (of unsigned chars); each element of the vector is set to 1 if the flow for the corresponding features has been found, otherwise, it is set to 0. 
     err output vector of errors; each element of the vector is set to an error for the corresponding feature, type of the error measure can be set in flags parameter; if the flow wasn't found then the error is not defined (use the status parameter to find such cases). 
    */ 
    Video.calcOpticalFlowPyrLK(matOpFlowPrev, matOpFlowThis, mMOP2fptsPrev, mMOP2fptsThis, mMOBStatus, mMOFerr); 

    cornersPrev = mMOP2fptsPrev.toList(); 
    cornersThis = mMOP2fptsThis.toList(); 
    byteStatus = mMOBStatus.toList(); 

    y = byteStatus.size() - 1; 

    for (x = 0; x < y; x++) { 
     if (byteStatus.get(x) == 1) { 
      pt = cornersThis.get(x); 
      pt2 = cornersPrev.get(x); 

      Core.circle(mRgba, pt, 5, colorRed, iLineThickness - 1); 

      Core.line(mRgba, pt, pt2, colorRed, iLineThickness); 
      } 
     } 

return mRgba; 

    }