I'm trying to use getpts to get the location of the selected points by the user.

I used it as follows:

[X,Y] = getpts(imread('xyz.jpg'));

But, got the following error:

Error using getpts (line 46)
First argument is not a valid handle.

Error in program (line 7)
[X,Y] = getpts(imread('xyz.jpg'));

Why is that?

Thanks.

有帮助吗?

解决方案

getpts needs a handle to either a figure or an axes, not a matrix as given by imread.

The simple solution is to display the image, then input either gca or gcf to getpts. Or you can manage handles on your own, but I don't think you wan't to do that.

Or to put it on one line with imshow:

[X,Y] = getpts(get(imshow('xyz.jpg'),'Parent'));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top