简体   繁体   English

通过MATLAB的像素位置

[英]Pixel location through MATLAB

I am working on a project where I have to find a certain object on a platform using an attached camera through MATLAB . 我正在开展一个项目,我必须通过MATLAB使用附加的相机在平台上找到某个对象。 I thought about using the platform as a grid, but I've been told that using the pixels of the camera, I might be able to get that position precisely by clicking on the camera window/screen and choosing a certain pixel (where the objects are going to show on the camera window/screen). 我想过将平台用作网格,但我被告知使用相机的像素,我可以通过点击相机窗口/屏幕并选择某个像素(对象的位置)来精确地获得该位置将在相机窗口/屏幕上显示)。

Is there a way to calculate the location of the object (clicked pixel) or is there any possible way I could do that? 有没有办法计算对象的位置(点击像素)或有什么方法可以做到这一点?

Try using the ginput(...) function in MATLAB, like this: 尝试在MATLAB中使用ginput(...)函数,如下所示:

% Load some image:
data = imread('fishy 01.jpg');

% display the image:
figure(88);
clf;
h = imagesc(data);
axis image

% Get a value from the screen:
[x, y] = ginput(1);

msgbox(['You want pixel: ' num2str(round([x,y]))]);

This will give you the location of the pixel in the current axis. 这将为您提供当前轴中像素的位置。 Alternately you, could use the figure callback WindowButtonUpFcn to get the current mouse position in the figure then translate that over to the axis you want it relative to, then scale to the current axis xlim and ylim. 或者,您可以使用图形回调WindowButtonUpFcn来获取图中的当前鼠标位置,然后将其转换为您想要的相对轴,然后缩放到当前轴xlim和ylim。 But ginput(1) will be much easier. 但是ginput(1)会容易得多。

示例运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM