2016-08-31 2 views
0

알고리즘 출력과 함께 opencv를 사용하여 표시된 이미지를 촬영할 수 있습니까? this처럼이 방법은 효율적이지 않은 스크린 샷 (powr + vol dwn)을 사용하여 만들어집니다.컬러 얼룩 검출기로 이미지 촬영하기 Opencv

Color blob 감지 출력을 포함하고 싶습니다. 스크린 샷 방법을 사용했지만 문제는 opencv에서 이미지를 가져 오는 방법이 다르기 때문에 항상 검은 색이라는 것입니다. 당신은 당신이 실제로 이미 이미지가 OpenCV의에서 ColorBlobDetection 예에 사용하거나 구축하는 경우

답변

0

나는이 맞다면 당신은 단지 등 주요 이미지가 아닌 헤더 메뉴 모음

을 원하는 가정하고있어 ColorBlobDetectionActivity의 'onCameraFrame'메소드의 결과물에 여러분이 필요하다고 생각합니다. 즉, mRgba 매트릭스가 반환되었습니다.

imwrite를 사용하여 저장하거나 저장할 수 있어야합니다.

다음은 테스트를 거쳐 작동하는 예제 코드입니다. 실제로 모든 프레임에서이 작업을 수행하지 않고 일부 트리거가 설정된 경우 한 번 수행하는 것이 좋지만 아래 코드는 일반적인 아이디어를 제공합니다.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

당신은 m도 수행해야합니다

당신이 당신의 매니페스트에 외부에 쓸 수있는 권한을 포함해야합니다 : 조심하는

public Mat onCameraFrame(CvCameraViewFrame inputFrame) { 
     mRgba = inputFrame.rgba(); 

     if (mIsColorSelected) { 
      mDetector.process(mRgba); 
      List<MatOfPoint> contours = mDetector.getContours(); 
      Log.e(TAG, "Contours count: " + contours.size()); 
      Imgproc.drawContours(mRgba, contours, -1, CONTOUR_COLOR); 

      Mat colorLabel = mRgba.submat(4, 68, 4, 68); 
      colorLabel.setTo(mBlobColorRgba); 

      Mat spectrumLabel = mRgba.submat(4, 4 + mSpectrum.rows(), 70, 70 + mSpectrum.cols()); 
      mSpectrum.copyTo(spectrumLabel); 

      File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); 
      String testFilename = "TestOCVwrite.png"; 
      File testFile = new File(path, testFilename); 
      String testFullfileName = testFile.toString(); 
      Log.i(TAG, "Writing to filename: " + testFilename); 
      Boolean writeResult = Imgcodecs.imwrite(testFullfileName, mRgba); 
      if (!writeResult) { 
       Log.i(TAG, "Failed to write to filename: " + testFilename); 
      } 
     } 

     return mRgba; 
    } 

어떤 것들은 png, jpeg 등 파일 이름에 파일 유형을 포함 시키면 오류가 발생합니다.

could not find a writer for the specified extension in function bool cv::imwrite_(const cv::String&, const cv::Mat&, const std::vector&, bool)

관련 문제