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

50 vues (au cours des 30 derniers jours)
GMD Baloch
GMD Baloch le 17 Avr 2019
Commenté : 鹤严 le 3 Mai 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

Réponses (2)

DGM
DGM le 20 Avr 2022
Modifié(e) : DGM le 20 Avr 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 le 17 Avr 2019
Modifié(e) : Clay Swackhamer le 17 Avr 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 commentaire
GMD Baloch
GMD Baloch le 19 Avr 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

Connectez-vous pour commenter.

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by