001/* 002 * Copyright (C) Photon Vision. 003 * 004 * This program is free software: you can redistribute it and/or modify 005 * it under the terms of the GNU General Public License as published by 006 * the Free Software Foundation, either version 3 of the License, or 007 * (at your option) any later version. 008 * 009 * This program is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU General Public License for more details. 013 * 014 * You should have received a copy of the GNU General Public License 015 * along with this program. If not, see <https://www.gnu.org/licenses/>. 016 */ 017 018package org.photonvision.vision.pipe.impl; 019 020import org.opencv.core.Core; 021import org.opencv.core.Mat; 022import org.photonvision.vision.opencv.ImageRotationMode; 023import org.photonvision.vision.pipe.MutatingPipe; 024 025/** Pipe that rotates an image to a given orientation */ 026public class RotateImagePipe extends MutatingPipe<Mat, RotateImagePipe.RotateImageParams> { 027 public RotateImagePipe() { 028 setParams(RotateImageParams.DEFAULT); 029 } 030 031 public RotateImagePipe(RotateImageParams params) { 032 setParams(params); 033 } 034 035 /** 036 * Process this pipe 037 * 038 * @param in {@link Mat} to be rotated 039 * @return Rotated {@link Mat} 040 */ 041 @Override 042 protected Void process(Mat in) { 043 Core.rotate(in, in, params.rotation.value); 044 return null; 045 } 046 047 public static class RotateImageParams { 048 public static RotateImageParams DEFAULT = new RotateImageParams(ImageRotationMode.DEG_0); 049 050 public ImageRotationMode rotation; 051 052 public RotateImageParams() { 053 rotation = DEFAULT.rotation; 054 } 055 056 public RotateImageParams(ImageRotationMode rotation) { 057 this.rotation = rotation; 058 } 059 } 060}