auto.js B0037 每日答题代码 2021-10-24


toast("每日答题")
var question = ""
var Title = ""
function GetQuestion(){
    sleep(1000)
    // className("android.view.View").text("查看提示").findOne().click();
    // sleep(1000)
    widget = className("android.view.View").find();
    log(widget.length)
    jj = 0
    for (i = 0; i < widget.length; i++) {
        widgetText = widget[i].text();
        if (widgetText != "") {
            question += widgetText;
            //indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。
            if (widgetText.indexOf('学】') > -1 || widgetText.indexOf('学]') > -1) {
                break
            }
        }
    }

    if (question.indexOf("题】") != -1) { //【单选题】【多选题】
        var index = question.indexOf("题】")
        question = question.substring(index + 2, question.length)
    }
    if (question.indexOf("【出题:武汉大学】") != -1) {
        var index = question.indexOf("【出题:武汉大学】")
        question = question.substring(0, index)
    }
    if (question.indexOf("[question来源:") != -1) {    //[question来源:湘潭大学西安交通大学上海交通大学]
        var index = question.indexOf("[question来源:")
        question = question.substring(0, index)
    }

    //对获取的question进行处理,去除所有特殊字符
    pattern = /[`~!@#$^&*()=|{}':;'“”,\\\[\]\.<>\/?~!@#¥……&*()——|{}【】';:""'。,、?\s]/g;
    question = question.replace(pattern, "")
    log(question)
    log("****字符串截取**********")
    log(question.substring(10,45))
    return question
}

function SingleChoice() {
    toastLog("进入单选题1")
    //获取所有字符串,包括题目答案。  查找查看提示控件的父控件
    var tips = className("android.view.View").text("查看提示").findOne(8000).parent()
    if(tips){
        sleep(1000);
        tips.click();
    }else{
        toastLog("单击提示出错。")
    }
    sleep(2000)
    //获取所有文字
    Title = GetQuestion();
    log("######################")
    log(Title)//所有字符串
    log("######################")
    
    //ABCD在题目和答案中出现的次数
    var SChoices = className("android.view.View").depth(13).indexInParent(2).find()
    log(SChoices.length)
    //多选就是全选
    for (var i = 0; i < SChoices.length; i++) {
        var tv = SChoices[i];
        if (tv) {
            toastLog(tv.text());
            sleep(1500);
        }
    }

}
function MultipleChoice() {
    toastLog("进入多选题2")
    var Choices = className("android.widget.CheckBox").depth(13).find()
    // log(Choices)
    log("******************")
    log(Choices.length)//childCount不可以使用
    //多选就是全选
    for (var i = 0; i < Choices.length; i++) {
        var tv = Choices[i];
        if (tv) {
            var tr = tv.bounds();
            click(tr.centerX(), tr.centerY());
            sleep(1500)
        }
    }

    var ChoiceTure = className("android.view.View").text("确定").findOne(8000)
    if (ChoiceTure) {
        ChoiceTure.click()
        sleep(2000)
    } else {
        toastLog("多选题确定失败.")
    }
}
//Fill in the blanks
function FillBlanks() {
    toastLog("进入填空题3")
}

function dailyAns() {
    sleep(800)//
    //每日答题  获取题目类型   多选题(全选)  填空题 OK 单选题
    var title = className("android.view.View").depth(11).drawingOrder(0).indexInParent(0).findOne(5000)

    if (title) {
        log(title.text())
        sleep(1000);
    } else {
        toastLog("未获取题目")
    }

    //对 单选  多选  填空  分别处理
    if (title.text() == "单选题") {
        SingleChoice();
    }
    else if (title.text() == "多选题") {
        MultipleChoice();
    }
    else if (title.text() == "填空题") {
        FillBlanks();
    }
    else {
        toastLog("错误-单选-多选-填空")
    }



    // className("android.widget.ListView").findOne(1000).child(10).child(3).click()//进入订阅
    // sleep(1000)
    // var Newspaper = className("android.widget.ImageView").depth(12).indexInParent(2).findOne()//
    // log(Newspaper)
    // if (Newspaper) {
    //     toastLog("订阅。。。。。")
    //     // Newspaper.click()//进入学习积分页面  项目列表
    //     sleep(2000);
    // }

}

dailyAns()

版本2

toast("每日答题")
var question = ""
var Title = ""
var ChoiceTimes = 0;
var timesS = 0;//单选出现次数
var ChoiceC = "";//单选最终答案

//单击  确定  下一题  完成
function NextTureOver() {
    //单击确定。。下一题
    toastLog("单选:确定、下一题、完成3个问题的选择。")
    var ChoiceTure = className("android.view.View").text("确定").findOne(2000)
    var ChoiceNext = className("android.view.View").text("下一题").findOne(2000)
    var ChoiceOver = className("android.view.View").text("完成").findOne(2000)
    if (ChoiceTure) {
        toastLog("ChoiceTure");
        ChoiceTure.click();
        sleep(2000);
    } else if (ChoiceNext) {
        toastLog("ChoiceNext");
        ChoiceNext.click();
        sleep(2000);
    } else {
        toastLog("ChoiceOver");
        ChoiceOver.click();
        sleep(2000);
    }
}

function StrTimes(str, keyWord) {
    let sumNum = 0;
    if (str) {
        let arr = str.split(keyWord);
        sumNum = arr.length - 1;
    }
    return sumNum
}

function GetQuestion() {
    sleep(1000)
    // className("android.view.View").text("查看提示").findOne().click();
    // sleep(1000)
    widget = className("android.view.View").find();
    log(widget.length)
    jj = 0
    for (i = 0; i < widget.length; i++) {
        widgetText = widget[i].text();
        if (widgetText != "") {
            question += widgetText;
            //indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。
            if (widgetText.indexOf('学】') > -1 || widgetText.indexOf('学]') > -1) {
                break
            }
        }
    }

    if (question.indexOf("题】") != -1) { //【单选题】【多选题】
        var index = question.indexOf("题】")
        question = question.substring(index + 2, question.length)
    }
    if (question.indexOf("【出题:武汉大学】") != -1) {
        var index = question.indexOf("【出题:武汉大学】")
        question = question.substring(0, index)
    }
    if (question.indexOf("[question来源:") != -1) {    //[question来源:湘潭大学西安交通大学上海交通大学]
        var index = question.indexOf("[question来源:")
        question = question.substring(0, index)
    }

    //对获取的question进行处理,去除所有特殊字符
    pattern = /[`~!@#$^&*()=|{}':;'“”,\\\[\]\.<>\/?~!@#¥……&*()——|{}【】';:""'。,、?\s]/g;
    question = question.replace(pattern, "")
    log(question)
    log("****字符串截取**********")
    log(question.substring(10, 45))
    return question
}

function SingleChoice() {
    toastLog("进入单选题1")
    //获取所有字符串,包括题目答案。  查找查看提示控件的父控件
    var tips = className("android.view.View").text("查看提示").findOne(8000).parent()
    if (tips) {
        sleep(1000);
        tips.click();
    } else {
        toastLog("单击提示出错。")
    }
    sleep(2000)
    //获取所有文字
    Title = GetQuestion();
    log("######################")
    log(Title)//所有字符串
    log("######################")

    //获取所有文字后back
    sleep(1000)
    back();
    //ABCD在题目和答案中出现的次数
    var SChoices = className("android.view.View").depth(13).indexInParent(2).find()
    log("选项共有:" + SChoices.length)
    //多选就是全选   相似度计算
    for (var i = 0; i < SChoices.length; i++) {
        sleep(1000)
        var tv = SChoices[i];
        if (tv) {
            toastLog(tv.text());
            log("--------------------------------------")
            log(StrTimes(Title, tv.text()))
            var timesS = StrTimes(Title, tv.text())
            if (ChoiceTimes < timesS) {
                click(tv.bounds().centerX(), tv.bounds().centerY());
                ChoiceTimes = timesS;
                log(tv.text() + "出现过" + timesS)
                // ChoiceC=tv.text();
            }
            log("--------------------------------------")
            sleep(1500);
        }
        
    }
    //单击确定。。下一题
    toastLog("单选:确定、下一题、完成3个问题的选择。")
    NextTureOver();
}
function MultipleChoice() {
    toastLog("进入多选题2")
    var Choices = className("android.widget.CheckBox").depth(13).find()
    // log(Choices)
    log("******************")
    log(Choices.length)//childCount不可以使用
    //多选就是全选
    for (var i = 0; i < Choices.length; i++) {
        var tv = Choices[i];
        if (tv) {
            var tr = tv.bounds();
            click(tr.centerX(), tr.centerY());
            sleep(1500)
        }
    }

    toastLog("多选:确定、下一题、完成3个问题的选择。")
    NextTureOver();
}

//Fill in the blanks
function FillBlanks() {
    toastLog("进入填空题3")//随便输入后面完善
    setText("共产党万岁中华民族万岁");
    sleep(1000)
    //单击确定。。下一题
    className("android.view.View").text("确定").findOne(6000).click()
    sleep(1000)
    if (className("android.view.View").text("完成").findOne(6000)) {
        className("android.view.View").text("完成").findOne(6000).click();
        sleep(1000)
    }

    toastLog("填空:确定、下一题、完成3个问题的选择。")
    NextTureOver();
}

function DailyAns() {
    //每日答题有五道题循环五次
    for (i = 0; i < 5; i++) {
        sleep(800)//
        //每日答题  获取题目类型   多选题(全选)  填空题 OK 单选题
        var title = className("android.view.View").depth(11).drawingOrder(0).indexInParent(0).findOne(5000)

        if (title) {
            log(title.text())
            sleep(1000);
        } else {
            toastLog("未获取题目")
        }

        //对 单选  多选  填空  分别处理
        if (title.text() == "单选题") {
            SingleChoice();
        }
        else if (title.text() == "多选题") {
            MultipleChoice();
        }
        else if (title.text() == "填空题") {
            FillBlanks();
        }
        else {
            toastLog("错误-单选-多选-填空")
        }
        var title=""//清除数据要不下一次会选错题目
    }
}

DailyAns();
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要使用opencv-python编写一个答题卡识别程序,可以按照以下步骤进行: 1. 导入必要的库和模块 ```python import cv2 import numpy as np ``` 2. 读入图片并进行预处理 ```python img = cv2.imread('test.jpg', cv2.IMREAD_GRAYSCALE) blur = cv2.GaussianBlur(img, (5, 5), 0) thresh = cv2.adaptiveThreshold(blur, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 11, 2) ``` 3. 检测轮廓并筛选出答题卡区域 ```python contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) for c in contours: area = cv2.contourArea(c) if area > 5000: peri = cv2.arcLength(c, True) approx = cv2.approxPolyDP(c, 0.02 * peri, True) if len(approx) == 4: card = approx break ``` 4. 对答题卡区域进行透视变换 ```python width, height = 1000, 1200 pts1 = np.float32([card[0], card[1], card[2], card[3]]) pts2 = np.float32([[0, 0], [width, 0], [0, height], [width, height]]) matrix = cv2.getPerspectiveTransform(pts1, pts2) dst = cv2.warpPerspective(img, matrix, (width, height)) ``` 5. 对透视变换后的图像进行二值化处理,提取轮廓并识别答案 ```python gray = cv2.cvtColor(dst, cv2.COLOR_BGR2GRAY) _, thresh = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY_INV) contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) for c in contours: area = cv2.contourArea(c) if area > 100: x, y, w, h = cv2.boundingRect(c) roi = thresh[y:y + h, x:x + w] roi = cv2.resize(roi, (28, 28)) roi = roi / 255.0 roi = roi.reshape(1, 28, 28, 1) # 使用模型对答案进行识别 result = model.predict([roi]) pred = np.argmax(result[0]) cv2.rectangle(dst, (x, y), (x + w, y + h), (0, 255, 0), 2) cv2.putText(dst, str(pred), (x, y), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2) ``` 这样就可以完成一个简单的答题卡识别程序了。注意:此处省略了模型的训练和加载过程,需要在程序中进行相应的处理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值