correct quadrant and angle when not using roipoly

Hi I'm trying to make 2 objects in a picture the points of interest however, the problem I'm facing is that I can't get the angle of the point of interest. the simpler solution would be to do it with roipoly but then i wont understand the how...
The picture contains the 2 lego platforms I intend to mark as points of interests but when selecting the right one I get a square with the background table. So in the code I need to account for the angle, I'm trying to make all my codes more general purpouse hens the switch case i know i should implement it in a loop for more objects than two but that comes later at the moment i just need to solve this hurdle.
cam = webcam;
img_piece = snapshot(cam);
figure;imshow(img_piece);
hold on;
roi1 = drawpolygon;
mask1 = createMask(roi1);
draw(roi1);
mask2 = createMask(roi1);
mask = mask1 + mask2;
pause
maskedImg = img_piece;
for i = 1:size(img_piece,1)
for j = 1:size(img_piece,2)
if ~mask(i,j)
maskedImg(i,j,:) = [0 0 0];
end
end
end
figure;imshow(maskedImg);
%% EDIT: the code now contains the correct answer but for multiple uses you need to make it your own

 Respuesta aceptada

Image Analyst
Image Analyst el 2 de En. de 2021
Editada: Image Analyst el 2 de En. de 2021

0 votos

You need to use roipolyold() or drawpolygon() instead of all that with ginput(), etc.

5 comentarios

yea I've played around with roipoly that's why i'm doing this to understand a bit better. drawpolygon() is new to me so I guess I'll do some testing with it ones I get home.
kishan s
kishan s el 4 de En. de 2021
Hello
I'm facing the same issue as you have described your problem.
I also need to mask the region of interest without using ROIPOLY.
I have been tried too hard but everthing gone in vain.
Did you got any answers for that or any other method by which we can create ROI without using ROIPOLY?
Thanks in advance
krishan, did you give draw() a try?
I'm at a loss I just don't know how to "turn of" everything but the region drawn by the drawpolygon() function because i get a 4x2 array and don't know how to make that into the "area" if the angle is unknown. I guess i could work one out with cosinrule and sin but is this really the easiest way to code? Then I might just aswell keep the ginput() and start the maths....
There is! just needed to add mask = createMask() updating the thread and thanking you for the guidance.

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2020b

Preguntada:

el 2 de En. de 2021

Editada:

el 5 de En. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by