How to make an image straightener like that of cam scanner app?

65 visualizaciones (últimos 30 días)
GMD Baloch
GMD Baloch el 17 de Abr. de 2019
Comentada: 鹤严 el 3 de Mayo de 2023
Hello, everyone, I want to make an application just like camScanner which lets the user to select the corners of the object and then straights the image according to those corners in such a way that the text is still readable. I need help in this context

Respuestas (2)

DGM
DGM el 20 de Abr. de 2022
Editada: DGM el 20 de Abr. de 2022
Dead post, I know, but you can use image transformation tools like imwarp() to do the perspective correction.
A = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/214874/56260471_568057093678369_4947302863245148160_n.jpg');
% these are the coordinates of the box corners
% you can get these using getpts() or impixelinfo() or datatips
boxm = [28 3; % [x y]
31 959;
1297 783;
1343 195];
% assert that this is where they're supposed to be
% any coordinates that define a rectangle
boxf = [30 30; % [x y]
30 900;
1300 900;
1300 30];
TF = fitgeotrans(boxm,boxf,'projective');
outview = imref2d(size(A));
B = imwarp(A,TF,'fillvalues',255,'outputview',outview);
imshow(B)
Normally, the easy way would be to just find the corners of the board, but since they aren't visible, just pick points that define a quadrilateral whose sides are apparently parallel to the board edges.
After the transformation, you may elect to crop the result and do further post-processing. Gotta love that glare, ghosting, and the feeble smudges of half-dry markers. Reminds me why I can't stand whiteboards.
B = imcrop(B,[14 33 1332 869]); % crop it
B = imflatfield(B,40); % try to suppress the glare
B = imadjust(B,[0.4 0.65]); % adjust levels
imshow(B)
You might be able to clean it up a bit further with some morphological operations. The compression artifacts are really going to end up being a limiting factor. That, and some of the written text is no darker than the ghost text.
B = imcomplement(imbothat(B,ones(7)));
imshow(B)

Clay Swackhamer
Clay Swackhamer el 17 de Abr. de 2019
Editada: Clay Swackhamer el 17 de Abr. de 2019
Hi GMD,
Here is a bit of code where I implemented this type of thing. The objective was to straighten a calibration ruler so that it would be aligned with the image borders. I'll attach the image showing the scale before it was rotated and an image showing the rotated scale. The gist of the code is that I find the "hypotenuse" as in the diagonal line that connects the far corners of the scale, then depending on which way it is going I decide whether to rotate the image clockwise or counterclockwise. Since your implementation will be a bit different I'll skip the rest of the code but hopefully this gives you the main idea.
%Decide which way to rotate the image
if (slope > 0) %Look like negative slopes
angle_rotate = 45 - abs(angle_hypot);
field_rotated = imrotate(field, -angle_rotate);
elseif (slope <= 0) %Look like positive slopes
angle_rotate = 45 - abs(angle_hypot);
field_rotated = imrotate(field, angle_rotate);
end
  1 comentario
GMD Baloch
GMD Baloch el 19 de Abr. de 2019
Thankyou for answering but you didn't get my point, I have an image given in attachment and I want to extract the whiteboard's pixels and then want to straight it like a rectangle

Iniciar sesión para comentar.

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by