多校联赛四之找边界 License Plate Recognition HDU - 6993

本文介绍了一个关于数字图像处理的项目——车牌字符识别系统。系统分为三个模块:车牌定位、字符分割和字符识别。重点讨论了字符分割模块,该模块的目标是找到每个字符的左右边界。给定二值化图像后,通过寻找像素变化来确定字符边界。代码示例展示了如何实现这一过程,从右向左找到每个字符的结束边界,然后从左向右找到汉字的起始边界。此问题的输入和输出格式也进行了详细说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:https://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1009&cid=987
Little Rabbit is a college student who is studying Communication Engineering. In this term, he has a course called Digital Image Processing. At the end of the course, Little Rabbit needs to complete a project called License Plate Recognition, in which Little Rabbit should program a system to recognize the characters of a license plate in an image.

A classic License Plate Recognition system has three modules:
License Plate Localization: to localize the license plate in the image.

Character Segmentation: to segment the image so that the characters of the license plate can be separated.

Character Recognition: to recognize the characters in the image and get the result string.
To complete the project, Little Rabbit builds a team of three members. Each member is in charge of one module. Here, Little Rabbit is in charge of the second module — Character Segmentation.

After the License Plate Localization module and some preprocessing, Little Rabbit gets some binary images that represent the license plates. The binary images are all 100 pixels in width and 30 pixels in height, containing only black pixels and white pixels. The black pixels represent the background, and the white pixels represent the characters.

Little Rabbit’s task is to segment the binary images so that the characters in the images can be separated. According to the standard, there are seven characters in a license plate, lining up from left to right. Specifically, Little Rabbit’s task is to find the left boundary and the right boundary of each character.

Let’s consider the images as matrices with 30 rows and 100 columns. Then number the columns 1 to 100 from left to right. We define the left boundary of a character as the index of the column where the leftmost pixel is located, and the right boundary as the index of the column where the rightmost pixel is located. For example, in the following picture, the left boundary of the character is 3, and the right boundary is 7.

在这里插入图片描述

Now given the binary images that Little Rabbit needs to segment, please output the left boundary and the right boundary of each character. In this problem, we use . to represent a black pixel, and # to represent a white pixel.
Input
The first line contains an integer T (1≤T≤50) — the number of test cases.

Each test case represents a binary image, which contains 30 lines of strings. Each line contains 100 characters, either . (a black pixel) or # (a white pixel).

Here are all the characters that may appear in the image.

Chinese characters:

在这里插入图片描述

ASCII version: https://paste.ubuntu.com/p/B5pTWv7s6J/
(Backup: https://github.com/cjj490168650/plate/blob/main/chn.txt)

English and numeric characters:

在这里插入图片描述

ASCII version: https://paste.ubuntu.com/p/59bjvwY3Yr/
(Backup: https://github.com/cjj490168650/plate/blob/main/eng.txt)

It is guaranteed that:
The characters in the image follow the standard of license plates. There are seven characters in the image, lining up from left to right. The first character is a Chinese character. The second character is an English character. The last five characters are English or numeric characters.

All characters in the image are identical to the characters given above (ASCII version), including the size and the shape.

There are no redundant white pixels in the image.

There is spacing between characters.

The characters won’t touch or get out of the image boundaries.
Output
For the x-th test case, output Case #x: in the first line.

Then in the next seven lines, the i-th line contains two integers separated by a space character, indicating the left boundary and the right boundary of the i-th character.
Sample Input
样例格式搞不定,图片如下
在这里插入图片描述

1







…##…##…#####…########…##…########…
…#…#…###…##…#######…########…###…########…
…#…#…###…##…##…##…###…###…##…
…#…#…####…##…##…###…####…##…
…###############…####…##…##…###…####…##…
…#…#…##.#…##…##…###…####…##…
…#…#…##.##…##…##…#####…#####…#######…
…#…#…##.##…##…##…######…##.##…########…
…#…#…###.##…##…###…##…###.##…###…
…#########…##…##…##…###…##…##…##…##…
…#…#…##…#…##…##…##…##…##…##…
…#…#…##…##…##…###…##…##…##…##…
…#…#…#######…##…###…##…##…#########…##…
…#…#…########…##…##…##…##…#########…##…##…
…#########…##…##…##…###…###…##…##…##…###…
…#…#…##…##…##…########…######…##…#######…
…##…##…##…########…####…##…#####…






Sample Output
Case #1:
5 19
24 32
40 41
50 58
63 70
76 84
89 97

题意

图中一个七个字符,找出每个字符的左右边界

思路

将有 # 的列记为 1,没有为0 ,然后寻找每个字符对应的左右边界即可。从右向左找出每个字符的左右边界,由于川,鄂字中间有间隔,所以对汉字的左边界再次查找,从左到右找到第一个字符,即为汉字的左边界

代码

#include<bits/stdc++.h>
using namespace std;
char a[40][110];
int s[110];
struct node
{
    int x,y;
}p[110];
int main()
{
    int t,k1=0;
    scanf("%d",&t);
    while(t--)
    {
        k1++;
        memset(s,0,sizeof(s));
        for(int i=0;i<30;i++)
            scanf("\n%s",a[i]);

        for(int i=0;i<100;i++)
        {
            for(int j=0;j<30;j++)
            {
                if(a[j][i]=='#')
                {
                    s[i]=1;
                    break;
                }
            }
        }
        int k=0;
        for(int i=99;i>0;i--)
        {
            if(s[i]==0&&s[i-1]==1)
                p[k++].y=i;
        }
        int l=0;
        for(int i=99;i>0;i--)
        {
            if(s[i]==1&&s[i-1]==0)
                p[l++].x=i+1;
        }
        for(int i=0;i<100;i++)
        {
            if(s[i]==1)
            {
                 p[6].x=i+1;
                 break;
            }
        }
        printf("Case #%d:\n",k1);
        for(int i=6;i>=0;i--)
            printf("%d %d\n",p[i].x,p[i].y);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值