Foren: English (Thread #11015)

How to pre-rotate a QRCode? (2006-05-10 11:56 by drhu00 #21774)

I just find out that most failure case of decoding scanned image is due to the mini rotation of the image.

For example, if a QRCode be rotate one degree, then the decode will probably fail. If I rotate it back before decoding, it will success. The question is how can we pre-rotate the image to the right position.

Reply to #21774×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Anmelden

RE: How to pre-rotate a QRCode? (2006-05-10 14:05 by yanbe #21779)

I think so too. Current CVS source is more based on specification than previous releases and be able to decode more versions. But in camera-scanned, rotated images, decoder sometimes indicate less recognition rate from v0.5,

In short, we can get symbol's angle with FinderPattern.getAngle(). But our decoder does not rotate images currently. In exchange, sampling grid generator try to fit it.

But as you see, this approach sometimes generate sampling grid with gap.

Therefore, I think it's worth to challenge to pre-rotate the image for better decoding. And this process will corresponds affine-translation technique.
Reply to #21774

Reply to #21779×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Anmelden

RE: How to pre-rotate a QRCode? (2006-05-11 01:58 by Anonym #21785)

I have been thinking about how to preprocess snapshots to improve the results of the decoder. <a href="http://csdl2.computer.org/persagen/DLAbsToc.jsp?resourcePath=/dl/proceedings/&toc=comp/proceedings/cw/2004/2140/00/2140toc.xml&DOI=10.1109/CW.2004.23">Here</a> an interesting paper about an algorithm which could be useful.


--
Carlos Abalde (carlos.abalde@gmail.com)
Reply to #21774

Reply to #21785×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Anmelden

RE: How to pre-rotate a QRCode? (2006-05-11 04:23 by drhu00 #21788)

I do find a good sitehttp://www.TinyLine.com which provide iamge rotate for J2ME and I tested it, it works great. So If we can know how many degrees to rotate to align the image, then we solved our problem. And also the finderPattern can simplify a lot since if the image align we don't need the sincos angle and the sampling grid can be simlify also. yanbe, can you provide a simple call to get the rotate degree if passing in the Image?
Reply to #21774

Reply to #21788×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Anmelden

RE: How to pre-rotate a QRCode?  (2006-05-13 12:50 by yanbe #21834)

Yes, it looks very good idea.
Ok, I'll do this task in a second.
Reply to #21774

Reply to #21834×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Anmelden

RE: RE: How to pre-rotate a QRCode? (2006-07-06 07:45 by Anonym #23568)

Hi, I also need to rotate the QR image.
I have a hard time understand the degree rotated though.
cuz in the output:
Angle*4098: Sin 87381 Cos 4194304
(this one is 1 degree clockwise rotation).
I have hard time reading and understand the number.
Can anyone help??
Reply to #21774

Reply to #23568×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Anmelden

RE: RE: RE: How to pre-rotate a QRCode? (2006-07-06 11:10 by yanbe #23571)

Sorry for inconvenience.

Because our target platform (J2ME CLDC1.0) does not have floating-point related data type or class (float and Float), I selected "pseudo fix point calculation" approach.

You will see DECIMAL_POINT constant in some source code. To reduce calculation error, original values ( < 1.0) are bit-shifted to left with this constant. This is why you saw such a big values.

Thus, you can get original sin/cos value by bit-shifting right with DECIMAL_POINT on other environment. You can check if values you got are correct or not by this step.

I recognize that this is not good interface. But I have no idea without this approach when I implemented this part. And this approach still bring s some calculation error. Then, I want to fix it to better code. Ff you have any algorithm or idea about this problem, please tell it us.

Thanks.
Reply to #23568

Reply to #23571×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Anmelden

RE: How to pre-rotate a QRCode? (2006-07-07 07:42 by johncmt #23603)

I finally figure the angle out, and I have registered as well
I modified some code that tell you how many degree to rotate for your QR symbol
here is the (funcition static int[] getAngle(Point[] centers)) in FinderPattern



//&#402;V&#402;“&#402;{&#402;&#8249;&#8218;ÌŒXŽÎŠp“x&#8218;ð&#8249;?&#8218;ß&#8218;é
static int[] getAngle(Point[] centers) {

Line[] additionalLine = new Line[3];

for (int i = 0; i < additionalLine.length; i++) {
additionalLine[i] = new Line(centers[i],
centers[(i + 1) % additionalLine.length]);
}
Line longestLine = Line.getLongest(additionalLine);
Point originPoint = new Point();
for (int i = 0; i < centers.length; i++) {
if ((centers[i].getX() != longestLine.getP1().getX() ||
centers[i].getY() != longestLine.getP1().getY()) &
(centers[i].getX() != longestLine.getP2().getX() ||
centers[i].getY() != longestLine.getP2().getY())) {
originPoint = centers[i];
break;
}
}
Point remotePoint = new Point();


//?¶?ã&#8218;Ì&#402;p&#402;^?[&#402;“’†?S“_&#8218;ðŒ´“_&#8218;Æ&#8218;&#181;&#8218;Ä?A‘&#188;&#8218;Ì2&#402;p&#402;^?[&#402;“&#8218;Ì’†?S“_&#8218;ª&#8218;Ç&#8218;±&#8218;É&#8218; &#8218;é&#8218;©
//&#8218;¨&#8218;æ&#8218;Ñ?AŠp“xŒv‘ª&#8218;Ì‘Î?Û&#8218;Æ&#8218;È&#8218;é“_&#8218;Í&#8218;&#187;&#8218;ê&#8218;ç&#8218;Ì&#8218;¤&#8218;¿&#8218;Ç&#8218;¿&#8218;ç&#8218;©
if (originPoint.getY() <= longestLine.getP1().getY() & //‘æ1&#8218;Ü&#8218;&#189;&#8218;Í‘æ2?ÛŒÀ
originPoint.getY() <= longestLine.getP2().getY())
if (longestLine.getP1().getX() < longestLine.getP2().getX())
remotePoint = longestLine.getP2();
else
remotePoint = longestLine.getP1();
else if (originPoint.getX() >= longestLine.getP1().getX() & //‘æ2&#8218;Ü&#8218;&#189;&#8218;Í‘æ3?ÛŒÀ
originPoint.getX() >= longestLine.getP2().getX())
if (longestLine.getP1().getY() < longestLine.getP2().getY())
remotePoint = longestLine.getP2();
else
remotePoint = longestLine.getP1();
else if (originPoint.getY() >= longestLine.getP1().getY() & //‘æ3&#8218;Ü&#8218;&#189;&#8218;Í‘æ4?ÛŒÀ
originPoint.getY() >= longestLine.getP2().getY())
if (longestLine.getP1().getX() < longestLine.getP2().getX())
remotePoint = longestLine.getP1();
else
remotePoint = longestLine.getP2();
else //‘æ1&#8218;Ü&#8218;&#189;&#8218;Í‘æ4?ÛŒÀ
if (longestLine.getP1().getY() < longestLine.getP2().getY())
remotePoint = longestLine.getP1();
else
remotePoint = longestLine.getP2();

int r = new Line(originPoint, remotePoint).getLength();
int sincos[] = new int[2];
sincos[0] = ((remotePoint.getY() - originPoint.getY()) << QRCodeImageReader.DECIMAL_POINT) / r; //Sin
sincos[1] = ((remotePoint.getX() - originPoint.getX()) << QRCodeImageReader.DECIMAL_POINT) / r; //Cos

//John test for output value
double x = remotePoint.getX() - originPoint.getX();
double y =remotePoint.getY() - originPoint.getY();
//System.out.println("point x=" + x);
//System.out.println("point y=" + y);
double tempRad = Math.atan(x/y); // degree need to become 90 degree (from 0-180) or 270 (from 180-360)
double tempDegree = Math.toDegrees(tempRad);

//convert value to int
int decimalPlace = 0;
BigDecimal bd = new BigDecimal(tempDegree);
bd = bd.setScale(decimalPlace,BigDecimal.ROUND_UP);
tempDegree = bd.doubleValue();

//if angle == 0, no rotation needed
if (y == 0 && x > 0){
System.out.println("Your angle is: 0");
System.out.println("To correct rotation, rotate clockwise: 0");
}else if (y == 0 && x < 0){ //angle @ 180, rotate 180
System.out.println("Your angle is: 180");
System.out.println("To correct rotation, rotate clockwise: 180");
}else if (x == 0 && y > 0){ //anlge @ 90, rotate 270)
System.out.println("Your angle is: 90");
System.out.println("To correct rotation, rotate clockwise: 270");
}else if (x == 0 && y < 0){ //anlge @ 270, rotate 90)
System.out.println("Your angle is: 270");
System.out.println("To correct rotation, rotate clockwise: 90");
}else if (x > 0 && y > 0){ //angle between 0 to 90
int actualDegree = 90 - (int)tempDegree; //acutal degree you are in
int degreeRotate = 360 - actualDegree; // degree rotate need to fix the QR code
System.out.println("Your angle is: " + actualDegree);
System.out.println("To correct rotation, rotate clockwise: "+ degreeRotate);
}else if (x < 0 && y >0){ // angle between 90 and 180)
int actualDegree = 90 - (int)tempDegree; //acutal degree you are in
int degreeRotate = 360 - actualDegree; // degree rotate need to fix the QR code
System.out.println("Your angle is: " + actualDegree);
System.out.println("To correct rotation, rotate clockwise: "+ degreeRotate);
}else if (x < 0 && y < 0){ //angle between 180 and 270
int actualDegree = 270 - (int)tempDegree; //acutal degree you are in
int degreeRotate = 360 - actualDegree; // degree rotate need to fix the QR code
System.out.println("Your angle is: " + actualDegree);
System.out.println("To correct rotation, rotate clockwise: "+ degreeRotate);
}else if (x > 0 && y < 0){ // angle between 90 and 180)
int actualDegree = 270 - (int)tempDegree; //acutal degree you are in
int degreeRotate = 360 - actualDegree; // degree rotate need to fix the QR code
System.out.println("Your angle is: " + actualDegree);
System.out.println("To correct rotation, rotate clockwise: "+ degreeRotate);
}





//System.out.println("QRCodeImageReader.DECIMAL_POINT=" + QRCodeImageReader.DECIMAL_POINT);
//System.out.println("r=" + r);
// sincos[0] = (sincos[0] == 0) ? 1 : sincos[0];
// sincos[1] = (sincos[1] == 0) ? 1 : sincos[1];
return sincos;
}
Reply to #21774

Reply to #23603×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Anmelden

RE: How to pre-rotate a QRCode? (2006-07-07 11:02 by ln20001115 #23606)

I think it's easy to work out in image,which is rotated.hard to find that three points position for rotated image.if the image is screen by camera,it hard to find sense blocks position by 1:1:3:1:1.
Reply to #21774

Reply to #23606×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Anmelden