List of usage examples for org.opencv.core Core transpose
public static void transpose(Mat src, Mat dst)
From source file:ch.zhaw.facerecognitionlibrary.Helpers.MatOperation.java
License:Open Source License
/*************************************************************************************** * Title: Rotate image by 90, 180 or 270 degrees * Author: StereoMatching/*ww w . j a v a 2s .c o m*/ * Date: 29.04.2013 * Code version: - * Availability: http://stackoverflow.com * ***************************************************************************************/ public static void rotate_90n(Mat img, int angle) { if (angle == 270 || angle == -90) { // Rotate clockwise 270 degrees Core.transpose(img, img); Core.flip(img, img, 0); } else if (angle == 180 || angle == -180) { // Rotate clockwise 180 degrees Core.flip(img, img, -1); } else if (angle == 90 || angle == -270) { // Rotate clockwise 90 degrees Core.transpose(img, img); Core.flip(img, img, 1); } }
From source file:com.github.mbillingr.correlationcheck.ImageProcessor.java
License:Open Source License
Bitmap matToBitmap(Mat input) {
if (input == null) {
return Bitmap.createBitmap(0, 0, Bitmap.Config.ARGB_8888);
}/*from ww w . j a v a 2s .com*/
Mat tmp = new Mat();
if (input.channels() == 1) {
Imgproc.cvtColor(input, tmp, Imgproc.COLOR_GRAY2RGB);
} else {
Imgproc.cvtColor(input, tmp, Imgproc.COLOR_BGR2RGB);
}
Core.transpose(tmp, tmp);
Core.flip(tmp, tmp, 1);
Bitmap bm = Bitmap.createBitmap(tmp.cols(), tmp.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(tmp, bm);
return bm;
}
From source file:net.pandorica.opencv.pano.PanoActivity.java
License:Open Source License
/** * Prepares dialogs dynamic content//w ww . j a v a 2 s. c om */ @Override protected void onPrepareDialog(int id, Dialog dialog) { switch (id) { case DIALOG_RESULTS: refreshView(); Mat mIntermediate = new Mat(); Mat mYuv = new Mat(); mIntermediate = Highgui.imread(mDirPath + mSubDir + mImagePrefix + mCurrentImage + mType); Core.transpose(mIntermediate, mYuv); Core.flip(mYuv, mIntermediate, 1); Imgproc.resize(mIntermediate, mYuv, new Size(), 0.25, 0.25, Imgproc.CV_INTER_AREA); /** Currently Not Working in OpenCV **/ /* Bitmap jpg = Bitmap.createBitmap(mIntermediate.cols(), mIntermediate.rows(), Bitmap.Config.ARGB_8888); android.MatToBitmap(mIntermediate, jpg); */ /** So we resort to this method **/ Highgui.imwrite(mDirPath + mSubDir + mImagePrefix + mCurrentImage + smallType, mYuv); Bitmap jpg = BitmapFactory.decodeFile(mDirPath + mSubDir + mImagePrefix + mCurrentImage + smallType); /** **/ // cleanup mIntermediate.dispose(); mYuv.dispose(); ImageView image = (ImageView) dialog.findViewById(R.id.image); image.setScaleType(ImageView.ScaleType.CENTER_INSIDE); image.setAdjustViewBounds(true); image.setPadding(2, 2, 2, 2); image.setImageBitmap(jpg); Button capture = (Button) dialog.findViewById(R.id.capture); capture.setOnClickListener(new OnClickListener() { public void onClick(View v) { mCurrentImage++; capturePhoto(); } }); Button retake = (Button) dialog.findViewById(R.id.retake); retake.setOnClickListener(new OnClickListener() { public void onClick(View v) { capturePhoto(); } }); Button stitch = (Button) dialog.findViewById(R.id.stitch); stitch.setOnClickListener(new OnClickListener() { public void onClick(View v) { new StitchPhotoTask().execute(); } }); break; case DIALOG_SUCCESS: final File img = new File(mDirPath + mSubDir + mOutputImage); Bitmap result = BitmapFactory.decodeFile(img.getAbsolutePath()); ImageView png = (ImageView) dialog.findViewById(R.id.image); png.setScaleType(ImageView.ScaleType.CENTER_INSIDE); png.setAdjustViewBounds(true); png.setPadding(3, 3, 3, 3); png.setImageBitmap(result); refreshImage(mGalleryImage); refreshView(); Button share = (Button) dialog.findViewById(R.id.share); share.setOnClickListener(new OnClickListener() { public void onClick(View v) { shareImage(img); dismissDialog(DIALOG_SUCCESS); } }); Button exit = (Button) dialog.findViewById(R.id.close); exit.setOnClickListener(new OnClickListener() { public void onClick(View v) { dismissDialog(DIALOG_SUCCESS); } }); break; case DIALOG_FEATURE_COMPARISON: CheckBox box = (CheckBox) dialog.findViewById(R.id.show_tip); box.setChecked(mShowTip); box.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mShowTip = ((CheckBox) v).isChecked(); SharedPreferences settings = getSharedPreferences(SETTINGS, 0); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean(SETTINGS_SHOW_TIP, mShowTip); editor.commit(); } }); Button cont = (Button) dialog.findViewById(R.id.tip_continue); cont.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { capturePhoto(); } }); break; default: super.onPrepareDialog(id, dialog); } }
From source file:org.firstinspires.ftc.teamcode.vision.VisionLib.java
private Mat getCameraMat() { Image img = vuforia.getCurrentImage(); if (img != null) { //construct mat to store image data Mat matIn = new Mat(img.getHeight(), img.getWidth(), CvType.CV_8UC3); //convert pixel ByteBuffer to byte[] byte[] pixels = new byte[img.getPixels().remaining()]; img.getPixels().get(pixels);//w ww . j a v a 2 s. c om //put data matIn.put(0, 0, pixels); //rotate and convert Core.transpose(matIn, matIn); Core.flip(matIn, matIn, 1); Imgproc.cvtColor(matIn, matIn, Imgproc.COLOR_BGR2RGB); return matIn; } return null; }
From source file:processdata.depthDataProcessingUtilities.java
/** * converts depth data to opencv Mat object leaving depth values that are only within min and max thresholds * @param path//from www .ja v a2s . c o m * @param minThreshold * @param maxThreshold * @return * @throws FileNotFoundException */ public static Mat processDepthDataFile(String path, int minThreshold, int maxThreshold) throws FileNotFoundException { File depthData = new File(path); double[][] depthDataArray = new double[1][217088]; //read depth data into array int count = 0; inDepthDataFile = new Scanner(depthData);//.useDelimiter(",\\s*"); while (inDepthDataFile.hasNext()) { String currentStr = inDepthDataFile.nextLine(); if (!currentStr.isEmpty()) depthDataArray[0][count++] = Double.parseDouble(currentStr); } double depthDataMatrix[][] = new double[512][424]; depthDataMatrix = reshape(depthDataArray, 512, 424); Mat matDepthDataMatrix = new Mat(512, 424, CvType.CV_64F); //cut-off the remaining depth values for (int i = 0; i < depthDataMatrix.length; i++) { for (int j = 0; j < depthDataMatrix[0].length; j++) { if (depthDataMatrix[i][j] > maxThreshold || depthDataMatrix[i][j] < minThreshold) depthDataMatrix[i][j] = 0; } } //find max value double max = 0; for (int i = 0; i < depthDataMatrix.length; i++) { for (int j = 0; j < depthDataMatrix[0].length; j++) { if (depthDataMatrix[i][j] > max) max = depthDataMatrix[i][j]; } } //FILL THE DEPTH MATRIX //System.out.println("Max Element "+ max); for (int i = 0; i < depthDataMatrix.length; i++) { for (int j = 0; j < depthDataMatrix[0].length; j++) { matDepthDataMatrix.put(i, j, depthDataMatrix[i][j] / max * 255.0); } } // //printout the depth matrix // for(int i = 0;i<depthDataMatrix.length;i++){ // for(int j = 0;j<depthDataMatrix[0].length;j++){ // System.out.print(depthDataMatrix[i][j]+"\t"); // } // System.out.println(); // } // //apply colormap to visualize Mat processedMathDepthImage = new Mat(matDepthDataMatrix.size(), CvType.CV_8U); matDepthDataMatrix.convertTo(processedMathDepthImage, CvType.CV_8UC1); Core.transpose(processedMathDepthImage, processedMathDepthImage); org.opencv.contrib.Contrib.applyColorMap(processedMathDepthImage, processedMathDepthImage, org.opencv.contrib.Contrib.COLORMAP_JET); return processedMathDepthImage; }
From source file:samples.FtcTestOpenCv.java
License:Open Source License
/** * This method rotate the image to the specified angle. * * @param src specifies the image to be rotated. * @param dst specifies the destination to put the rotated image. * @param angle specifies the rotation angle. */// w w w. j a v a 2 s .com private void rotateImage(Mat src, Mat dst, double angle) { angle %= 360.0; if (angle == 0.0) { src.copyTo(dst); } else if (angle == 90.0 || angle == -270.0) { Core.transpose(src, dst); Core.flip(dst, dst, 1); } else if (angle == 180.0 || angle == -180.0) { Core.flip(src, dst, -1); } else if (angle == 270.0 || angle == -90.0) { Core.transpose(src, dst); Core.flip(dst, dst, 0); } else { Mat rotMat = Imgproc.getRotationMatrix2D(new Point(src.cols() / 2.0, src.rows() / 2.0), angle, 1.0); Imgproc.warpAffine(src, dst, rotMat, src.size()); } }
From source file:uk.ac.horizon.aestheticodes.controllers.MatTranform.java
License:Open Source License
static void rotate(Mat src, Mat dst, int angle, boolean flip) { if (src != dst) { src.copyTo(dst);// www. ja va 2s.c om } angle = ((angle / 90) % 4) * 90; //0 : flip vertical; 1 flip horizontal int flip_horizontal_or_vertical = angle > 0 ? 1 : 0; if (flip) { flip_horizontal_or_vertical = -1; } int number = Math.abs(angle / 90); for (int i = 0; i != number; ++i) { Core.transpose(dst, dst); Core.flip(dst, dst, flip_horizontal_or_vertical); } }
From source file:uk.ac.horizon.artcodes.detect.ImageBuffers.java
License:Open Source License
private void rotate(Mat image) { //0 : flip vertical; 1 flip horizontal int flip_horizontal_or_vertical = rotations > 0 ? 1 : 0; if (flip) {/*from w ww . j ava 2 s .co m*/ flip_horizontal_or_vertical = -1; } for (int i = 0; i != rotations; ++i) { Core.transpose(image, image); Core.flip(image, image, flip_horizontal_or_vertical); } }