Why is the rectangle() function not recognized?

I have a 2D floor plan image. I want to have bounding boxes around the rooms in it. When I use rectangle function to draw rectangles, error 'Unrecognised function of variable 'rectangle' '. Can somebody help me please?
Here is my code:
BW1=imread('wallimage_withnodoor.jpg');
BW1=im2bw(BW1);
Rooms = regionprops(BW1,'BoundingBox');
imshow(BW1); hold on
for k=1:length(Rooms)
currbb=Rooms(k).BoundingBox;
rectangle('Position',[currbb(1),currbb(2),currbb(3),currbb(4)], 'EdgeColor','r','LineWidth',2);
end
hold off
This is the error which I am getting:
Unrecognized function or variable 'rectangle'.
Error in classify_objects_test1 (line 46)
rectangle('Position',[currbb(k),currbb(2),currbb(3),currbb(4)], 'EdgeColor','r','LineWidth',2);
Here is the image I used:
I want to have the bounding boxes around each room in the image.

댓글 수: 8

type in command window
which rectangle
and post the answer here
which rectangle -all
Iam getting 'built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\graphics\primitive\rectangle)'
Is there more code than this? In particular, do you happen to use a variable named path ?
Yes still there is more code than this. That part is to identify objects in image. But there is no variable named path
dbstop if error
and run your code. When it stops,
which -all rectangle
Is it possible that you are running scripts (instead of calling functions), and at the same time you call load without any output arguments, and one of the .mat files being loaded includes a variable named rectangle ?
When there are potentially conflicts between variable names load()'d, and function names that are the same as the variable names, there are some cases where MATLAB can make arbitrary decisions about whether the name refers to a function or a variable.
You are right. It is working when I wrote it seperately.

댓글을 달려면 로그인하십시오.

답변 (1개)

madhan ravi
madhan ravi 2020년 5월 11일

0 개 추천

built-in (/MATLAB/toolbox/matlab/graphics/primitive/rectangle)
If you see other than the above after using
which rectangle -all
Y ou need to remove or rename those file/s.

댓글 수: 1

built-in (C:\Program Files\MATLAB\toolbox\matlab\graphics\primitive\rectangle)
What should I do now?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Computer Vision Toolbox에 대해 자세히 알아보기

질문:

2020년 5월 11일

댓글:

2020년 5월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by