image-rotation

How to straighten a tilted square shape in an image?

谁都会走 提交于 2019-12-04 05:41:47
问题 How can I straighten a tilted square shape in an image? I do not know the angle with which it is tilted and the code must calculate it and then rotate it automatically. For example, I have the following image: which should be rotated to give the following output image: 回答1: A simple way using only the top and bottom corners. Note that this approach relies on the upper and lower most corners: i = imread('sq.jpg'); i_bw = im2bw(i)==0; % Modify the strel as required se = strel('square', 10); i

AffineTransform truncates image

♀尐吖头ヾ 提交于 2019-12-04 02:09:30
问题 I have an image and I have to rotate it by 45, 90, 135, 180 degrees. What I am doing: try { BufferedImage src = ImageIO.read(new File("src.png")); double ang = Math.toRadians(90); AffineTransform t = new AffineTransform(); t.setToRotation(ang, src.getWidth() / 2, src.getHeight() / 2); AffineTransformOp op = new AffineTransformOp(t, null); BufferedImage dst = new BufferedImage(src.getWidth(), src.getHeight(), src.getType()); op.filter(src, dst); ImageIO.write(dst, "png", new File("output.png")

How to Determine and Auto-Rotate Images?

≡放荡痞女 提交于 2019-12-04 00:55:33
I have bunch of images, among them some of the images have to be rotated. Sample: I want to rotate this image 90° counter-clockwise. I Googled to know how can I rotate an image and found many links and SO threads. But how can I determine if the image needs to be rotated ? Picasa has a Auto-Rotating feature. I want to have similar functionality. Any pointer would be very helpful to me. I have found a link but it is related to Android. Tapas Bose The pointer of metadata-extractor which Roger Rowland has provided solved the problem. I am posting it here for future reference: import java.awt.geom

Align images based on a detected features in Opencv

穿精又带淫゛_ 提交于 2019-12-03 21:46:08
Hi I've a base image and other images that I'd like to rotate with the same angle as the base image. this is my base image. this is an example image that I'd like to rotate. here my full code. #include <stdio.h> #include <iostream> #include "opencv2/core/core.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/calib3d/calib3d.hpp" #include "opencv2/nonfree/nonfree.hpp" #include "opencv2/imgproc/imgproc.hpp" #define PI 3.14159265 using namespace cv; using namespace std; void rotate(cv::Mat& src, double angle, cv::Mat& dst) { int len = std:

display image between four corner points Matlab

*爱你&永不变心* 提交于 2019-12-03 21:37:56
问题 Suppose I have 4 corner points : (x1, y1) ; (x2, y2) ;(x3, y3) ; (x4, y4) and a rectangular image size (m,n) How do I display the image such that the image when shown has its corners at the four mentioned points. In other words, four corners can control the angle at which the image is rotated (bear in mind the image edges might not be parallel) Thanks! 回答1: You need to warp the image for a generalized solution. You can do it as follows: First, Read the image. img=imread('cameraman.tif'); if

Rotating hundreds of JPEGs in seconds rather than hours

試著忘記壹切 提交于 2019-12-03 20:14:17
We have hundreds of images which our computer gets at a time and we need to rotate and resize them as fast as possible. Rotation is done by 90, 180 or 270 degrees. Currently we are using the command line tool GraphicsMagick to rotate the image. Rotating the images (5760*3840 ~ 22MP) takes around 4 to 7 seconds. The following python code sadly gives us equal results import cv img = cv.LoadImage("image.jpg") timg = cv.CreateImage((img.height,img.width), img.depth, img.channels) # transposed image # rotate counter-clockwise cv.Transpose(img,timg) cv.Flip(timg,timg,flipMode=0) cv.SaveImage(

Positioning image on Google Maps with rotate / scale / translate

别等时光非礼了梦想. 提交于 2019-12-03 14:36:25
I'm developing a user-interface for positioning an image on a google map. I started from : http://overlay-tiler.googlecode.com/svn/trunk/upload.html which is pretty close to what I want. But instead of 3 contact points I want a rotate tool, a scale tool and a translate tool (the later exists). I tried to add a rotate tool but it doesn't work as I expected : I put a dot on the left bottom corner that control the rotation (around the center of the image). The mouse drag the control dot and I calculate the 3 others points. My code is based on the mover object but I changed the onMouseMove

Rotate a UIImage or UIView to a particular angle, NOT an amount of angle

我的梦境 提交于 2019-12-03 13:40:31
问题 Objective-C for iOS. How do I rotate an image or view TO a particular angle. I have tried the two methods below, but both rotate the AMOUNT of angle, not TO the angle. Basically I would like to call a method to rotate to 90' and then say call again of 180', and the image/view to finish at 180', NOT an addition of them both (270') which is what happens if I use either of the methods below. #define degreesToRadians(degrees) (M_PI * degrees / 180.0) myImage.transform =

Detect if a text image is upside down

让人想犯罪 __ 提交于 2019-12-03 07:27:57
问题 I have some hundreds of images (scanned documents), most of them are skewed. I wanted to de-skew them using Python. Here is the code I used: import numpy as np import cv2 from skimage.transform import radon filename = 'path_to_filename' # Load file, converting to grayscale img = cv2.imread(filename) I = cv2.cvtColor(img, COLOR_BGR2GRAY) h, w = I.shape # If the resolution is high, resize the image to reduce processing time. if (w > 640): I = cv2.resize(I, (640, int((h / w) * 640))) I = I - np

Rotate a UIImage or UIView to a particular angle, NOT an amount of angle

最后都变了- 提交于 2019-12-03 03:45:10
Objective-C for iOS. How do I rotate an image or view TO a particular angle. I have tried the two methods below, but both rotate the AMOUNT of angle, not TO the angle. Basically I would like to call a method to rotate to 90' and then say call again of 180', and the image/view to finish at 180', NOT an addition of them both (270') which is what happens if I use either of the methods below. #define degreesToRadians(degrees) (M_PI * degrees / 180.0) myImage.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); myImage.transform = CGAffineTransformRotate(myImage.transform,