2016-04-22 6 views
5

मैं onPictureTaken() कॉलबैक में जैसे ही तस्वीर ले ली गई थी, जैसे ही मैं एक छवि को संसाधित करने की कोशिश कर रहा हूं। जैसा कि मेरी समझ में था, मुझे बाइट सरणी को ओपनसीवी मैट्रिक्स में परिवर्तित करना चाहिए, लेकिन जब मैं ऐसा करने का प्रयास करता हूं तो पूरा ऐप फ्रीज हो जाता है। असल में मैंने यह सब किया था:ओपनसीवी ऑन पिक्चरटेकन के साथ एक छवि को कैसे संसाधित करें?

@Override 
public void onPictureTaken(byte[] bytes, Camera camera) { 
    Log.w(TAG, "picture taken!"); 

    if (bytes != null) { 
     Bitmap image = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); 
     Mat matImage = new Mat(); 

     // This is where my app freezes. 
     Utils.bitmapToMat(image, matImage); 

     Log.w(TAG, matImage.dump()); 
    } 

    mCamera.startPreview(); 
    mCamera.setPreviewCallback(this); 
} 

क्या किसी को पता है कि यह क्यों ठंडा होता है और इसे कैसे हल किया जाए?

नोट: मैंने आधार के रूप में OpenCV4Android ट्यूटोरियल 3 का उपयोग किया है।

अद्यतन 1:

Mat mat = Imgcodecs.imdecode(
    new MatOfByte(bytes), 
    Imgcodecs.CV_LOAD_IMAGE_UNCHANGED 
); 

अद्यतन 2: मैं भी बाइट (किसी भी सफलता के बिना) parste को इस प्रकार की कोशिश की है माना जाता है इस काम करना चाहिए, यह हालांकि मेरे लिए ऐसा नहीं किया।

Bitmap image = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); 
Mat mat = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8UC1); 
mat.put(0, 0, bytes); 

अद्यतन 3:

Mat mat = new Mat(1, bytes.length, CvType.CV_8UC3); 
mat.put(0, 0, bytes); 

न ही इस प्रकार किया यह मेरे लिए काम नहीं किया या तो:

Mat mat = new MatOfByte(bytes); 

उत्तर

0

मैं मेरा एक सहयोगी की कुछ मदद मिल गया है । वह निम्नलिखित कार्य करके इस समस्या को ठीक करने में कामयाब रहे:

BitmapFactory.Options opts = new BitmapFactory.Options(); // This was missing. 
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, opts); 

Mat mat = new Mat(); 
Utils.bitmapToMat(bitmap, mat); 

// Note: when the matrix is to large mat.dump() might also freeze your app. 
Log.w(TAG, mat.size()); 

उम्मीद है कि इस जो भी इस के साथ संघर्ष कर रहे हैं आप सभी की मदद करेंगे।

संबंधित मुद्दे