List of usage examples for org.opencv.android Utils matToBitmap
public static void matToBitmap(Mat mat, Bitmap bmp, boolean premultiplyAlpha)
From source file:de.hhn.android.licenseplatedecoder.decoder.CountryExtractor.java
/** * Constructor//from w w w . j a va 2s. co m * @param nativeAddress input image pointer address * @param withoutStripInputAddr image pointer address in order to store the cropped image without the blue strip */ public CountryExtractor(long nativeAddress, long withoutStripInputAddr) { this.nativeInputAddr = nativeAddress; this.withoutStripInputAddr = withoutStripInputAddr; this.withoutBlueStrip = new Mat(); /** OCR ENGINE INIT */ this.baseApi = new TessBaseAPI(); this.baseApi.setDebug(true); this.baseApi.init("/sdcard/", "blueBand"); // myDir + "/tessdata/eng.traineddata" must be present this.baseApi.setVariable("tessedit_char_whitelist", "ABCDFGHIKLOPRSTZ"); this.baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_CHAR); ArrayList<Mat> countryCode = getCharacters(); StringBuffer strb = new StringBuffer(); for (Mat elem : countryCode) { Bitmap pass = Bitmap.createBitmap(elem.cols(), elem.rows(), Bitmap.Config.ARGB_8888); Utils.matToBitmap(elem, pass, true); baseApi.setImage(pass); String recognizedText = baseApi.getUTF8Text(); strb.append(recognizedText); baseApi.clear(); pass.recycle(); } this.result = strb.toString(); baseApi.end(); baseApi = null; countryCode = null; }
From source file:de.hhn.android.licenseplatedecoder.decoder.LPSegmenter.java
/** * Constructor// w w w. j a va2 s . c o m * @param inputImageAddr input image pointer address * @param countryCode input country code */ public LPSegmenter(long inputImageAddr, int countryCode) { this.nativeInputAddr = inputImageAddr; this.countryCode = countryCode; Log.d("Segmenter", "Country Code: " + countryCode); /** OCR ENGINE INIT */ this.baseApi = new TessBaseAPI(); // INITIALIZATION DEPENDING OF THE COUNTRY CODE String languageDataset; String whitelist = null; String[] datasetWhitelist = getDatasetAndWhiteList(countryCode); languageDataset = datasetWhitelist[0]; whitelist = datasetWhitelist[1]; this.baseApi.init("/sdcard/", languageDataset); // myDir + "/tessdata/eng.traineddata" must be present this.baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_CHAR); this.baseApi.setVariable("tessedit_char_whitelist", whitelist); ArrayList<Mat> segChars = getCharacters(); StringBuffer strb = new StringBuffer(); for (Mat elem : segChars) { Imgproc.cvtColor(elem, elem, Imgproc.COLOR_BGR2GRAY); Bitmap pass = Bitmap.createBitmap(elem.cols(), elem.rows(), Bitmap.Config.ARGB_8888); Utils.matToBitmap(elem, pass, true); baseApi.setImage(pass); String recognizedText = baseApi.getUTF8Text(); // Log or otherwise display this string... strb.append(recognizedText); baseApi.clear(); pass.recycle(); } this.result = strb.toString(); baseApi.end(); baseApi = null; segChars = null; }
From source file:us.cboyd.android.dicom.DcmInfoFragment.java
License:Open Source License
public void updateDicomInfo() { mDicomObject = null;/*w ww .ja va2 s.c om*/ if ((mCurrDir != null) && (mFileList != null) && (mPosition >= 0) && (mPosition < mFileList.size())) { try { // Read in the DicomObject DicomInputStream dis = new DicomInputStream(new FileInputStream(getDicomFile())); //mDicomObject = dis.readFileMetaInformation(); mDicomObject = dis.readDicomObject(); dis.close(); // Get the SOP Class element DicomElement de = mDicomObject.get(Tag.MediaStorageSOPClassUID); String SOPClass = ""; if (de != null) SOPClass = de.getString(new SpecificCharacterSet(""), true); else SOPClass = "null"; Log.i("cpb", "SOP Class: " + SOPClass); // TODO: DICOMDIR support if (SOPClass.equals(UID.MediaStorageDirectoryStorage)) { showImage(false); mErrText.setText(mRes.getString(R.string.err_dicomdir)); } else { showImage(true); int rows = mDicomObject.getInt(Tag.Rows); int cols = mDicomObject.getInt(Tag.Columns); Mat temp = new Mat(rows, cols, CvType.CV_32S); temp.put(0, 0, mDicomObject.getInts(Tag.PixelData)); // [Y, X] or [row, column] double[] spacing = mDicomObject.getDoubles(Tag.PixelSpacing); double scaleY2X = spacing[1] / spacing[0]; // Determine the minmax Core.MinMaxLocResult minmax = Core.minMaxLoc(temp); double diff = minmax.maxVal - minmax.minVal; temp.convertTo(temp, CvType.CV_8UC1, 255.0d / diff, 0); // Set the image Bitmap imageBitmap = Bitmap.createBitmap(cols, rows, Bitmap.Config.ARGB_8888); Log.w("cpb", "test3"); Utils.matToBitmap(temp, imageBitmap, true); Log.w("cpb", "test4"); mImageView.setImageBitmap(imageBitmap); mImageView.setScaleX((float) scaleY2X); } // TODO: Add selector for info tag listing mTags = mRes.getStringArray(R.array.dcmtag_default); refreshTagList(); } catch (Exception ex) { showImage(false); mErrText.setText(mRes.getString(R.string.err_file_read) + mFileList.get(mPosition) + "\n\n" + ex.getMessage()); } } else { showImage(false); mErrText.setText(mRes.getString(R.string.err_unknown_state)); } }
From source file:us.cboyd.android.shared.ImageContrastView.java
License:Open Source License
public void setImageContrastCV(double brightness, double contrast, int colormap, boolean inv) { double diff = getWidth(); double ImWidth = (1 - (contrast / 100.0d)) * diff; double alpha = 255.0d / ImWidth; double beta = alpha * (-mMin); mLevel = ImWidth / 2.0d + (diff - ImWidth) * (1.0d - (brightness / 100.0d)); mMax = ImWidth + (diff - ImWidth) * (1.0d - (brightness / 100.0d)); mMin = (diff - ImWidth) * (1.0d - (brightness / 100.0d)); int i = 0;/* w ww.j ava2 s . co m*/ int n = (int) diff; Mat cmap = new Mat(1, n, CvType.CV_32S); for (i = 0; i < n; i++) { cmap.put(0, i, i); } if (inv) { alpha *= -1.0d; beta = 255.0d - beta; } cmap.convertTo(cmap, CvType.CV_8UC1, alpha, beta); if (colormap >= 0) { Contrib.applyColorMap(cmap, cmap, colormap); //applyColorMap returns a BGR image, but createBitmap expects RGB //do a conversion to swap blue and red channels: Imgproc.cvtColor(cmap, cmap, Imgproc.COLOR_RGB2BGR); } Bitmap cmapBitmap = Bitmap.createBitmap(n, 1, Bitmap.Config.ARGB_8888); Utils.matToBitmap(cmap, cmapBitmap, false); setImageBitmap(cmapBitmap); }