JAVA Set集合练习

1.使用TreeSet类实现定制排序(降序)

import java.util.*;

public class ert {
    public static void main(String[] args) {
        Set<Integer>set=new TreeSet<>();/*升序*/
        set.add(-7);
        set.add(-4);
        set.add(3);
        set.add(10);
        set.add(6);
        Iterator it=set.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
        /*升序排法
        Set<Integer>set2=new TreeSet<>(Compartor.reverseOrder());
         */
    }
}

2.运用Hashset打印一个图书发票

import java.util.Objects;
/*创建构造方法*/
public class bookself {
    String name;
    String author;
    double price;

    public bookself(String name, String author, double price) {
        this.name = name;
        this.author = author;
        this.price = price;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        bookself bookself = (bookself) o;
        return name.equals(bookself.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}


/*测试类排序*/
public class booker {
    public static void main(String[] args) {
        Set<bookself>set=new HashSet();
        bookself p1=new bookself("JAVA入门到精通第三版","明日科技著编",59.8);
        bookself p2=new bookself("JAVA Web入门到精通","明日科技著编",67.8);
        bookself p3=new bookself("JAVA从入门到精通<实例版>","明日科技著编",69.8);
        set.add(p1);
        set.add(p2);
        set.add(p3);
        Iterator<bookself>it=set.iterator();
        System.out.print("书名\t"+"              作者\t"+"           价格\t"+"\n");
        System.out.println("----------------------------------------------------\n");
        while (it.hasNext()){
            bookself its= (bookself) it.next();
            System.out.println(its.getName()+"\t"+its.getAuthor()+"\t"+its.price+"\n");



        }

    }
}

import numpy as np # 添加这行代码 from paddleocr import PaddleOCR import cv2 # 初始化OCR模型(自动下载预训练模型) # 参数说明: # - use_angle_cls=True 启用方向分类(适合倾斜文本) # - lang='ch' 支持中英文识别(默认包含英文) # - use_gpu=False 若未安装GPU版本,需手动关闭GPU加速 ocr = PaddleOCR(use_angle_cls=True, use_gpu=True) # 首次运行会自动下载模型 # 指定本地图片路径(替换为你的图片路径) img_path = r'C:\Users\86135\Desktop\OCRTEST\23.jpg' # 示例路径,注意保留开头的'r'防止转义 # 执行OCR识别 result = ocr.ocr(img_path, cls=True) # 解析并打印结果 for idx, line in enumerate(result): print(f"------ 第{idx+1}行文本识别结果 ------") for word_info in line: text = word_info[1][0] # 提取文本内容 confidence = word_info[1][1] # 提取置信度 coordinates = word_info[0] # 提取文字框坐标 print(f"文本: {text} | 置信度: {confidence:.2f}") print(f"坐标: {coordinates}\n") # 可选:用OpenCV可视化结果(需提前安装opencv-python) image = cv2.imread(img_path) for line in result: for word in line: points = [tuple(map(int, point)) for point in word[0]] # 绘制文字框 cv2.polylines(image, [np.array(points, dtype=np.int32)], isClosed=True, color=(0,255,0), thickness=2) # 标注识别文本 cv2.putText(image, word[1][0], points[0], cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255,0,0), 2) cv2.imshow('OCR Result', image) cv2.waitKey(0) cv2.destroyAllWindows()在以上代码基础上进行修改,实现Paddleocr识别出的词FA、FS、AS后面的字母是I不是1,把识别出的结果全部输出,不能只输出包含FA、FS、AS,输出结果区分大小写的功能。
05-28
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值