-3

I would like to fit a QR-code into qr code a curved image. I used polar form in MATLAB in order to get curved shape but I do not know how to fit my QR-code into this non-square image.

this is the curved shape that i generate by MATLAB using polar form

Thnak you!

Yuksel
  • 9
  • 3
  • just to clarify your question, do you just want to insert a square shape into that area? or do you actually want to *warp* your QR image to assume that shape? – Tasos Papastylianou Jul 28 '16 at 16:00
  • and how do you generate that shape? – Tasos Papastylianou Jul 28 '16 at 16:01
  • @TasosPapastylianou I would like to insert the qr-code into that shape, and than my new qr-code should be that shape. After that I want to put that new qr-code on a conic surface in order to have a square image by that perspective. Thanks. – Yuksel Jul 28 '16 at 16:30
  • Basically, I used p=polar(t, length*ones(length(t),1)); I calculate my conic-shape's radius and size of my qr code, than I found angles. with that information I plot the that curved shape. – Yuksel Jul 28 '16 at 16:32

2 Answers2

1

Here's a quick'n'dirty approach

[QR, map] = imread ('qr.png'); % indexed image, so we need to also get the map            

QR = ind2gray (QR, map);       % convert to grayscale

QR = fliplr (QR);              % x-axis moves rightwards, whereas angle t moves 
                               % leftwards, therefore flip left-to-right                            

[r, t] = ndgrid (1 : size (QR, 1), 1 : size (QR, 2)); % rows as radius,
                                                      % columns as angle

t = mat2gray (t);                          % Normalize angle in [0,1] range
t = ((-t) * deg2rad (20)) - deg2rad (80);  % Convert to [80,100] range

r = mat2gray (r);                          % similar approach for radius range
r = (r * 5) + 15;             

X = r .* cos (t);                          % convert polar to cartesian
Y = r .* sin (t);                               

scatter (X(:), Y(:), 1, QR(:))             % plot each cartesian pair as a 
                                           % plot point of size 1, and colour
                                           % taken from the QR matrix
colormap gray;                            
axis off;

Result:

enter image description here

Tasos Papastylianou
  • 21,371
  • 2
  • 28
  • 57
  • oh, just noticed that you want the curvature to go the other way. Just do `Y = r ./ sin (t);` instead of `.*` :) – Tasos Papastylianou Jul 28 '16 at 19:25
  • Good answer... the OP doesn't deserve it though :) – rayryeng Jul 29 '16 at 04:53
  • Hahah, why? I thought it was a nice little problem. I can see how someone would be stumped trying to solve this with a polar plot. Plus, it's only his first question here :) – Tasos Papastylianou Jul 29 '16 at 09:47
  • @TasosPapastylianou. Thank you very much. It is really helpful. Now, I can work on it in order to make it readable by camera. – Yuksel Jul 29 '16 at 16:47
  • @TasosPapastylianou I print the shape with appropriate length and angle, however, the new QR code was not readable, because the length of the bottom arc was not correct. If we think an open conical cup as a pie and on this pie, we have our QR code. The arc (QR) of bottom and top are different, also it needs to be calculated based on angles. – Yuksel Aug 06 '16 at 20:30
  • R'=4.1; % top radius r'=2.8; % bottom radius H=13.5; % height of cup a=5.3; % distance from top of the cup to qr code. k=5; % the height of QR code. b=H-k-a; % with basic geometric calculation, we can find x , y and b. x =29.2114 y = 42.7739 theta_pie =8.4555 % similarly we can find the angles phi_pie =10.2434 beta = 34.5070 If I select the height of QR code 5cm, the arcs of bottom and top lengths d =5.8057 %bottom_length p=5.5302 %top_length – Yuksel Aug 06 '16 at 20:30
  • @TasosPapastylianou. You can find the sketch of QR code below. I tried to use two different angles, unfortunately, I could not plot the correct shape. Would you give me some ideas? Thanks in advance – Yuksel Aug 06 '16 at 20:47
0

I tried to sketch the QR code on a pie with parameters

also, all parameters are defined

I hope it would help to understand the problem.

Yuksel
  • 9
  • 3
  • hm, so, essentially, you want to apply an appropriately transformed QR texture on the surface of an upright cone, such that if you were holding your phone vertically (e.g. aligned to the XZ plane), and the texture was facing towards your phone, you would want the projection of that texture to your phone to form a perfect square (i.e. the original QR shape), such that it could be read properly. Correct? – Tasos Papastylianou Aug 06 '16 at 22:57
  • That is right! The QR code will be on a cup and it should be facing towards the phone. Hence, I should see a perfect square from the camera. I wrote a basic code that calculating all parameters if the size of cup changes. – Yuksel Aug 07 '16 at 02:27
  • I have a fairly easy (from a theoretical point of view) solution in my mind, which I can help with a bit later when I have time, but, are you sure that simply printing a QR code on a cup wouldn't work? I think readers just read the alternating pattern, I'm not sure they particularly care about a strict shape ... – Tasos Papastylianou Aug 07 '16 at 08:33
  • Also, you *really* should have mentioned the *actual* problem way earlier, hahah. Classic [XY Problem](http://xyproblem.info) case! :p – Tasos Papastylianou Aug 07 '16 at 08:33
  • I wanted to solve it by myself. Sorry, at the beginning I could not define problem well. Because I wanted a starting point. With the polar form, I was able to generate the actual curve, however, I could not patch/insert QR code on that curve. I tried many times, but, readers were not able to decode the code. Then I realized that the arcs of the bottom and top lengths are not consisting. That is why readers could not read it. – Yuksel Aug 07 '16 at 16:40
  • @TasosPapastylianou – Yuksel Aug 28 '16 at 01:24
  • Hi Yuksel. I don't have time to work an a full solution for you at the moment, but the approach I had in mind was the following: 1) Find an equation for your cone, starting from the origin (0,0,0) and with z-axis (i.e. x=0, y=0) acting as the rotation axis. 2) Define an 2D ndgrid the size of the QR image + appropriate offsets to position it where you want on the cone in terms of Z and X coordinates. 3) If you treat the original QR image as the projection to the X/Z plane, you can find the corresponding coordinates on the surface of the cone. – Tasos Papastylianou Aug 29 '16 at 16:11
  • Then assuming your texture will be printed on a strip of paper, you want to cut a piece of paper corresponding to the area between two concentric circles, such that the top and bottom circle become parallel planes when applied over the cone, right? So basically "parallel" circles of increasing size along your cone correspond to concentric circles along the radius of your flat strip. So find the arc distances at each circle level, and translate that into arc distances on the right concentric circle on your flat strip. Once you have all points, use `scatter` as above. – Tasos Papastylianou Aug 29 '16 at 17:18
  • Hi TasosPapastylianou, – Yuksel Aug 30 '16 at 14:58
  • Hi Yuksel :) How are you getting on? – Tasos Papastylianou Aug 30 '16 at 15:00
  • Thank you for your comment. I already find all equation of the cone and I was trying a similar approach, however, did not get a substantial result. You are right, the top and bottom circles should be parallel because that is the basic concept that the QR code should look like a perfect square on a cup. I will apply what you proposed and see the result. Thanks again. – Yuksel Aug 30 '16 at 15:05