MATLAB ButtonDownFcn

发布于 2024-10-09 10:26:27 字数 203 浏览 4 评论 0 原文

我在 MATLAB 中有一个“光学字符识别”项目,需要您的帮助:

  1. 当用户在图像上按下鼠标时,我如何识别? 我尝试使用 ButtonDownFcn 执行此操作,但即使我只是打印消息 该消息未打印。

  2. 我想允许用户从图像中选择车牌。 我怎样才能做到这一点并保存所选区域的像素?

提前致谢。

I have a project of "Optical Character Recognition" in MATLAB and i need your help:

  1. how do i recognize when the user press the mouse on an image?
    i trying to do this with ButtonDownFcn but even when i just printing message
    the message is not printed.

  2. i want to allow the user to select the license plate from the image.
    how can i do this and save the Pixels of the selected area?

thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

睫毛上残留的泪 2024-10-16 10:26:27

解决您的两个问题:

  1. 我猜您正在尝试设置 图形窗口'ButtonDownFcn',它不会按您期望的方式工作。如果您想在用户单击图像时执行某些操作,则应确保设置 'ButtonDownFcn',而不是图窗窗口或坐标区对象。请注意 figure 属性文档 中的这一行(重点是我添加的):

    <块引用>
    <块引用>

    当指针位于图窗窗口中时按下鼠标按钮,但不在子对象(即 uicontrol、uipanel、axes 或axes 子对象)上方时执行


    这就是为什么您必须为您希望其工作的每个对象设置一个'ButtonDownFcn'。为图形窗口设置它不会使其自动适用于图形中的每个对象。下面是为图形和图像对象设置 'ButtonDownFcn' 的示例:

    img = imread('peppers.png'); %# 加载示例图像
    hFigure = 图; %# 创建一个图形窗口
    hImage = 图像(img); %# 绘制图像
    set(hFigure,'ButtonDownFcn',... %# 设置图窗的 ButtonDownFcn
        @(s,e) disp('你好'));
    set(hImage,'ButtonDownFcn',... %# 设置图像的ButtonDownFcn
        @(s,e) disp('世界'));
    

    请注意单击图像内部和外部如何显示不同的消息,因为每次都会为不同的对象调用 'ButtonDownFcn'。另请注意,如果单击其中一个轴的刻度线标签,则不会显示任何内容。这是因为坐标区对象有自己的 'ButtonDownFcn',未设置任何内容。

  2. 如果您有权访问图像处理工具箱,您可以使用该功能< a href="http://www.mathworks.com/help/toolbox/images/ref/imfreehand.html" rel="noreferrer">IMFREEHAND 让用户在其中绘制 ROI(感兴趣区域)图像。然后您可以使用 createMask 方法 创建图像的二进制掩码,其中 1 表示 ROI 内的像素,0 表示 ROI 外的像素。

Addressing your two questions:

  1. I'm guessing that you are trying to set the 'ButtonDownFcn' of the figure window, which won't work how you expect it to. If you want to do something when the user clicks on an image, you should make sure that you're setting the 'ButtonDownFcn' of the image, and not the figure window or the axes object. Note this line in the figure property documentation (emphasis added by me):

    Executes whenever you press a mouse button while the pointer is in the figure window, but not over a child object (i.e., uicontrol, uipanel, axes, or axes child).

    This is why you have to set a 'ButtonDownFcn' for each object you want it to work for. Setting it for the figure window won't make it work automatically for each object in the figure. Here's an example that sets the 'ButtonDownFcn' for the figure and an image object:

    img = imread('peppers.png');     %# Load a sample image
    hFigure = figure;                %# Create a figure window
    hImage = image(img);             %# Plot an image
    set(hFigure,'ButtonDownFcn',...  %# Set the ButtonDownFcn for the figure
        @(s,e) disp('hello'));
    set(hImage,'ButtonDownFcn',...   %# Set the ButtonDownFcn for the image
        @(s,e) disp('world'));
    

    Notice how clicking inside and outside the image displays a different message, since each calls the 'ButtonDownFcn' for a different object. Notice also that if you click on the tick mark label of one of the axes, nothing is displayed. This is because the axes object has its own 'ButtonDownFcn', which wasn't set to anything.

  2. If you have access to the Image Processing Toolbox you can use the function IMFREEHAND to have the user draw an ROI (region of interest) in the image. Then you can use the createMask method to create a binary mask of the image with ones for pixels inside the ROI and zeroes for pixels outside the ROI.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文