• 2021“MINIEYE杯”中国大学生算法设计超级联赛(4)1009. License Plate Recognition(模拟)


    Problem Description

    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.

    img

    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:

    img

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

    English and numeric characters:

    img

    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
    
    #include <bits/stdc++.h>
    using namespace std;
    char mp[33][205];
    int sum[33][205];
    char chuan[33][33] = {
    	"..#..........#",
    	"..#....#.....#",
    	"..#....#.....#",
    	"..#....#.....#",
    	"..#....#.....#",
    	"..#....#.....#",
    	"..#....#.....#",
    	"..#....#.....#",
    	"..#....#.....#",
    	"..#....#.....#",
    	".##....#.....#",
    	".#.....#.....#",
    	".#.....#.....#",
    	"##.....#.....#",
    	"#............#"
    };
    char e[33][33] = {
    	"####.####.#####",
    	"#..#.#..#.#..##",
    	"#..#.#..#.#..#.",
    	"#..#.#..#.#..#.",
    	"####.####.#.#..",
    	"..........#.#..",
    	".#######..#.##.",
    	"..........#..#.",
    	"#########.#...#",
    	"..#.......#...#",
    	".#######..#...#",
    	".......#..#####",
    	".......#..#....",
    	"......##..#....",
    	"...####...#...."
    };
    int n, m;
    bool check1(int x, int y) {
    	bool flag = 1;
    	// for(int j = x; j <= x + 13; j++) {//长14高15
    	// 	for(int i = )
    	// }
    	for(int i = x; i >= x - 14; i--) {
    		for(int j = y; j <= y + 13; j++) {
    			if(mp[i][j] != chuan[14 + (i - x)][j - y]) {
    				flag = 0;
    				break;
    			}
    		}
    	}
    	if(flag) return 1;
    	else return 0;
    }
    bool check2(int x, int y) {
    	bool flag = 1;
    	for(int i = x; i <= x + 14; i++) {
    		for(int j = y; j <= y + 14; j++) {
    			if(mp[i][j] != e[i - x][j - y]) {
    				flag = 0;
    				break;
    			}
    		}
    	}
    	if(flag) return 1;
    	else return 0;
    }
    int main() {
    	int t;
    	cin >> t;
    	
    	n = 30, m = 100;
    	int cnt = 0;
    	while(t--) {
    		memset(sum, 0, sizeof(sum));
    		cnt++;
    		for(int i = 1; i <= n; i++) {
    			scanf("%s", mp[i] + 1);
    		}
    		printf("Case #%d:
    ", cnt);
    		bool flag = 0, lst = 0;
    		for(int j = 1; j <= m; j++) {
    			for(int i = 1; i <= n; i++) {
    				sum[i][j] = sum[i - 1][j];
    				if(mp[i][j] == '#') sum[i][j]++;
    			}
    		}
    		int j;
    		for(j = 1; j <= m + 1; j++) {
    			if(sum[n][j] != 0) {
    				if(sum[n][j - 1] == 0) {
    					int k = 0;
    					for(int kk = 1; kk <= n; kk++) {//根据川的结构确定
    						if(sum[kk][j] == 1) {
    							k = kk + 1;
    							break;
    						}
    					}
    					flag = 1;
    					if(check1(k, j)) {
    						cout << j << " " << j + 13 << endl;
    						j += 14;
    						flag = 0;//!
    					} else if(check2(k - 1, j)) {
    						cout << j << " " << j + 14 << endl;
    						j += 15;
    						flag = 0;//!
    					}
    					else cout << j << " ";
    				} 
    			} else {
    				if(flag) {
    					cout << j - 1 << endl;
    					flag = 0;
    				}
    			}
    		}
    	}
    }
    //川!要特判!
    
  • 相关阅读:
    MySQL日期函数与日期转换格式化函数大全
    外设驱动库开发笔记19:BMP280压力温度传感器驱动
    外设驱动库开发笔记18:MS5837压力变送器驱动
    通讯接口应用笔记1:RS485通讯上下拉电阻的选择
    外设驱动库开发笔记17:MS5803压力变送器驱动
    外设驱动库开发笔记16:MS5536C压力变送器驱动
    Elasticserach学习笔记之Elasticsearch查询慢和集群慢查询日志配置
    Linux学习笔记之curl模拟get/post/delete/put请求
    ELK学习笔记之elasticsearch中 refresh 和flush区别
    Prometheus学习笔记之Prometheus是如何定义告警级别的
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/15076287.html
Copyright © 2020-2023  润新知