µÚÒ»¸ö£º¶¨ÒåÒ»¸ö¹Ø±Õµ±Ç°´°¿ÚµÄº¯Êý
// ¶¨ÒåÒ»¸ö¹Ø±Õµ±Ç°´°¿ÚµÄº¯Êý
function close() {
// ±¾Ê¾Àý´´½¨Ò»¸ö´øÓÐÒ»¸ö°´Å¥µÄ´°¿Ú£¬µã»÷°´Å¥¹Ø±Õµ±Ç°´°¿Ú
// ³õʼ»¯Ò»¸öеĻ£¨´°¿Ú£©
var ac = new activity();
// ¼ÓÔز¼¾Ö´úÂ룬ʹÓà LinearLayout Ìæ»» vertical
ac.loadXML(`
<LinearLayout>
<Button id="button1" text="µÚÒ»¸ö°´Å¥"/>
</LinearLayout>
`);
// »ñÈ¡°´Å¥µÄʵÀý
var btn = ac.findViewById("button1");
// È·±£°´Å¥¶ÔÏó²»ÎªnullºóÔÙÉèÖõã»÷ʼþ
if (btn) {
// ÉèÖð´Å¥µÄµã»÷ʼþ¼àÌýÆ÷
btn.setOnClickListener(function() {
// ÔÚÐÂÏß³ÌÖÐÖ´ÐÐ JavaScript ´úÂë
new thread().runJsCode(function fun() {
// ʹÓà console.log() ´òÓ¡ÐÅÏ¢
console.log('Ïß³ÌÖ´ÐдúÂë·ÀÖ¹Õ¼ÓÃUIÏß³Ì');
// ¹Ø±Õ´°¿Ú
ac.close();
}, "-Ïß³ÌÃû");
});
} else {
console.log("°´Å¥Î´ÕÒµ½£¬ÎÞ·¨ÉèÖõã»÷ʼþ¡£");
}
}
// ʾÀýµ÷ÓÃ
close(); // µ÷Óùرմ°¿ÚµÄº¯Êý£¬ÏÔʾ´ø°´Å¥µÄ´°¿Ú
- º¯Êý¶¨Ò壺
function close()
¶¨ÒåÁËÒ»¸öÃûΪclose
µÄº¯Êý£¬ÓÃÓÚ´´½¨Ò»¸öд°¿Ú²¢ÉèÖð´Å¥µÄµã»÷ʼþ¡£ - ´°¿Ú³õʼ»¯£º
var ac = new activity();
´´½¨Ò»¸öеĻʵÀý£¬´ú±íÒ»¸öеĴ°¿Ú¡£ - ²¼¾Ö¼ÓÔØ£ºÊ¹ÓÃ
ac.loadXML(...)
·½·¨¼ÓÔØ XML ¸ñʽµÄ²¼¾Ö£¬Ê¹ÓÃLinearLayout
ÈÝÆ÷°üº¬ÁËÒ»¸ö°´Å¥Button
¡£ - °´Å¥»ñÈ¡£º
var btn = ac.findViewById("button1");
ͨ¹ý°´Å¥µÄ ID »ñÈ¡ÆäʵÀý¡£ - µã»÷ʼþÉèÖãº
- ͨ¹ýÅжÏ
btn
ÊÇ·ñΪ¿Õ£¬È·±£°´Å¥´æÔÚ¡£ - ʹÓÃ
btn.setOnClickListener(...)
ÉèÖõã»÷ʼþ£¬µ±°´Å¥±»µã»÷ʱ£¬»áÖ´ÐÐÆäÖеĴúÂë¡£
- ͨ¹ýÅжÏ
Ïß³ÌÖ´ÐУºÊ¹ÓÃ
new thread().runJsCode(...)
Æô¶¯ÐÂÏß³ÌÀ´Ö´ÐдúÂë¡£´°¿Ú¹Ø±Õ£º
ac.close();
¹Ø±Õµ±Ç°´°¿Ú¡£
µÚ¶þ¸ö£º¶¨ÒåÒ»¸ö¹Ø±ÕÓ¦Óõĺ¯Êý
// ¶¨ÒåÒ»¸ö¹Ø±ÕÓ¦Óõĺ¯Êý
function closeApp(arg0) {
// Õâ¸öº¯ÊýµÄ×÷ÓÃÊǹرÕÖ¸¶¨Ãû³ÆµÄÓ¦ÓÃ
// ²ÎÊý£º
// String arg0: ÐèÒª¹Ø±ÕµÄÓ¦ÓðüÃû (package name)
// ¼ì²é´«ÈëµÄ°üÃûÊÇ·ñΪ¿Õ
if (arg0 != "") {
// ÕâÀï¿ÉÒÔ¼ÓÈë¹Ø±ÕÓ¦ÓõÄÂß¼£¬±ÈÈçͨ¹ý API ¹Ø±ÕÓ¦ÓÃ
console.log("ÕýÔڹرÕÓ¦ÓÃ: " + arg0);
// ¹Ø±ÕÓ¦ÓõÄÏà¹ØÂß¼´úÂë
// ʾÀý£ºµ÷ÓÃϵͳ API À´¹Ø±ÕÓ¦Óã¨ÀýÈç Android ÉϵÄÏà¹ØÂß¼£©
} else {
// Èç¹û°üÃûΪ¿Õ£¬Êä³öÌáʾÐÅÏ¢
console.log("δÌṩ°üÃû£¬ÎÞ·¨¹Ø±ÕÓ¦Óá£");
}
}
// ʾÀýµ÷ÓÃ
app.closeApp("com.liubowang.drawingboard"); // µ÷ÓùرÕÓ¦Óõĺ¯Êý£¬¹Ø±Õ°üÃûΪ "com.liubowang.drawingboard" µÄÓ¦ÓÃ
// Èô²»Ìṩ°üÃûµÄÇé¿ö
app.closeApp(""); // Õ⽫Êä³öδÌṩ°üÃûµÄÌáʾ
º¯Êý¶¨Ò壺
function closeApp(arg0)
£º¶¨ÒåÁËÒ»¸öÃûΪcloseApp
µÄº¯Êý£¬½ÓÊÜÒ»¸ö²ÎÊýarg0
£¬¸Ã²ÎÊýÊÇÐèÒª¹Ø±ÕµÄÓ¦ÓõİüÃû£¬Í¨³£ÒÔ×Ö·û´®ÐÎʽÌṩ¡£
²ÎÊý˵Ã÷£º
String arg0
: ×÷ΪÊäÈ룬Õâ¸ö²ÎÊý´ú±íÒª¹Ø±ÕµÄÓ¦ÓõİüÃû£¬Àý×ÓÈç"com.liubowang.drawingboard"
¡£
°üÃû¼ì²é£º
if (arg0 != "")
: ¸ÃÌõ¼þÅжÏÓï¾äÓÃÀ´¼ì²é´«ÈëµÄ²ÎÊýarg0
ÊÇ·ñΪ¿Õ¡£Èç¹û°üÃû²»Îª¿Õ£¬±íʾÓÐÓÐЧµÄÓ¦ÓÃÐèÒª¹Ø±Õ¡£
Êä³ö¹Ø±ÕÐÅÏ¢£º
console.log("ÕýÔڹرÕÓ¦ÓÃ: " + arg0);
: ½«¹Ø±ÕÓ¦ÓõÄÐÅÏ¢´òÓ¡µ½¿ØÖÆ̨£¬ÓÐÖúÓÚµ÷ÊÔºÍÈ·ÈϲÙ×÷¡£
¹Ø±ÕÓ¦ÓõÄÂß¼£º
- Õâ¸ö²¿·Ö¿ÉÒÔ°üº¬Êµ¼ÊµÄ´úÂëÂß¼£¬ÓÃÓڹرÕÓ¦Ó᣾ßÌåʵÏÖ½«ÒÀÀµÓÚ²»Í¬Æ½Ì¨µÄ API¡£ÀýÈ磬ÔÚ Android ÖУ¬¿ÉÒÔʹÓÃijЩϵͳµ÷ÓÃÀ´½áÊø½ø³Ì¡£
- ʾÀýÖÐÌáµ½µÄ
android.os.Process.killProcess(android.os.Process.myPid());
ÊÇÒ»ÖֹرÕÓ¦Óýø³ÌµÄ·½Ê½£¬¾ßÌåÐèÒª¸ù¾Ýʵ¼ÊÒµÎñ³¡¾°À´¾ö¶¨ÊÇ·ñʹÓá£
´¦Àí¿Õ°üÃû£º
- Èç¹û
arg0
Ϊ¿Õ£¬º¯Êý½«Ö´ÐÐconsole.log("δÌṩ°üÃû£¬ÎÞ·¨¹Ø±ÕÓ¦Óá£");
£¬·´À¡¸øÓû§Î´ÌṩÓÐЧµÄ°üÃû£¬´Ó¶ø±ÜÃâÖ´ÐÐÎÞЧ»ò´íÎóµÄ²Ù×÷¡£
- Èç¹û
ʾÀýµ÷Óãº
app.closeApp("com.liubowang.drawingboard");
ÊÇʵ¼Êµ÷Óú¯ÊýµÄ·½Ê½£¬³¢ÊԹرÕÖ¸¶¨µÄÓ¦Óá£app.closeApp("");
ÊÇÒ»¸öʾÀý£¬±íÃ÷Èç¹û²»´«Èë°üÃû£¬½«ÌáʾÓû§Î´Ìṩ°üÃûµÄ´íÎó¡£
µÚÈý¸ö£º¹Ø±ÕfloatUIËùÓд°¿Ú
// ¶¨ÒåÒ»¸ö¼òµ¥µÄ FloatWindow ¹¹Ô캯ÊýÀ´Ä£Ä⸡¶¯´°¿Ú
function FloatWindow(name) {
this.name = name;
console.log(this.name + " ´°¿ÚÒÑ´ò¿ª");
}
FloatWindow.prototype.close = function() {
console.log(this.name + " ´°¿ÚÒѹرÕ");
};
// ¶¨ÒåÒ»¸ö floatUI ¹¹Ô캯ÊýÀ´¹ÜÀí¸¡¶¯´°¿Ú
function floatUI() {
this.windows = [];
}
floatUI.prototype.addWindow = function(name) {
var window = new FloatWindow(name);
this.windows.push(window);
};
floatUI.prototype.closeAll = function() {
this.windows.forEach(function(window) {
window.close();
});
this.windows = []; // Çå¿Õ´°¿ÚÊý×é
console.log("ËùÓд°¿ÚÒѹرÕ");
};
// ´´½¨Ò»¸ö floatUI ʵÀý²¢Ìí¼ÓһЩ¸¡¶¯´°¿Ú
var ui = new floatUI();
ui.addWindow("´°¿Ú1");
ui.addWindow("´°¿Ú2");
ui.addWindow("´°¿Ú3");
// ¹Ø±ÕËùÓи¡¶¯´°¿Ú
ui.closeAll();
¶¨Òå
FloatWindow
¹¹Ô캯Êýfunction FloatWindow(name) { this.name = name; console.log(this.name + " ´°¿ÚÒÑ´ò¿ª"); }
* µ±ÄãʹÓà `new FloatWindow(name)` ´´½¨Ò»¸öÐÂʵÀýʱ£¬»áÔÚ¿ØÖÆ̨Êä³ö´°¿ÚÒÑ´ò¿ªµÄÐÅÏ¢¡£
¶¨Òå
FloatWindow
µÄclose
·½·¨FloatWindow.prototype.close = function() { console.log(this.name + " ´°¿ÚÒѹرÕ"); };
* µ±Äãµ÷Óà `window.close()` ·½·¨Ê±£¬»áÔÚ¿ØÖÆ̨Êä³ö´°¿ÚÒѹرյÄÐÅÏ¢¡£
¶¨Òå
floatUI
¹¹Ô캯Êýfunction floatUI() { this.windows = []; }
* µ±ÄãʹÓà `new floatUI()` ´´½¨Ò»¸öÐÂʵÀýʱ£¬»á³õʼ»¯Ò»¸ö¿ÕÊý×é `windows` ÓÃÓÚ´æ´¢¸¡¶¯´°¿Ú¶ÔÏó¡£
¶¨Òå
floatUI
µÄaddWindow
·½·¨floatUI.prototype.addWindow = function(name) { var window = new FloatWindow(name); this.windows.push(window); };
* µ±Äãµ÷Óà `ui.addWindow(name)` ·½·¨Ê±£¬»á´´½¨Ò»¸öÐ嵀 `FloatWindow` ¶ÔÏ󣬲¢½«ÆäÌí¼Óµ½ `ui.windows` Êý×éÖС£Í¬Ê±£¬`FloatWindow` µÄ¹¹Ô캯Êý»áÔÚ¿ØÖÆ̨Êä³ö´°¿ÚÒÑ´ò¿ªµÄÐÅÏ¢¡£
¶¨Òå
floatUI
µÄcloseAll
·½·¨floatUI.prototype.closeAll = function() { this.windows.forEach(function(window) { window.close(); }); this.windows = []; // Çå¿Õ´°¿ÚÊý×é console.log("ËùÓд°¿ÚÒѹرÕ"); };
* µ±Äãµ÷Óà `ui.closeAll()` ·½·¨Ê±£¬»á±éÀú `ui.windows` Êý×éÖеÄÿ¸ö `FloatWindow` ¶ÔÏ󣬲¢µ÷ÓÃÆä `close` ·½·¨À´¹Ø±Õ´°¿Ú¡£Ã¿¸ö´°¿Ú¹Ø±Õʱ£¬`FloatWindow` µÄ `close` ·½·¨»áÔÚ¿ØÖÆ̨Êä³ö´°¿ÚÒѹرյÄÐÅÏ¢¡£×îºó£¬Çå¿Õ `ui.windows` Êý×飬²¢ÔÚ¿ØÖÆ̨Êä³öËùÓд°¿ÚÒѹرյÄÐÅÏ¢¡£
Ö´Ðйý³Ì
´´½¨
floatUI
ʵÀývar ui = new floatUI();
* ¿ØÖÆ̨Êä³ö£ºÎÞ£¨ÒòΪ `floatUI` ¹¹Ô캯ÊýÖÐûÓÐÊä³öÐÅÏ¢£©
Ìí¼Ó¸¡¶¯´°¿Ú
ui.addWindow("´°¿Ú1"); ui.addWindow("´°¿Ú2"); ui.addWindow("´°¿Ú3");
* ¿ØÖÆ̨Êä³ö£º
´°¿Ú1 ´°¿ÚÒÑ´ò¿ª
´°¿Ú2 ´°¿ÚÒÑ´ò¿ª
´°¿Ú3 ´°¿ÚÒÑ´ò¿ª
¹Ø±ÕËùÓи¡¶¯´°¿Ú
ui.closeAll();
* ¿ØÖÆ̨Êä³ö£º
´°¿Ú1 ´°¿ÚÒѹرÕ
´°¿Ú2 ´°¿ÚÒѹرÕ
´°¿Ú3 ´°¿ÚÒѹرÕ
ËùÓд°¿ÚÒѹرÕ
×ܽá
ÔÚÖ´ÐÐ ui.addWindow("´°¿Ú1")
¡¢ui.addWindow("´°¿Ú2")
ºÍ ui.addWindow("´°¿Ú3")
ʱ£¬¿ØÖÆ̨»áÊä³öÿ¸ö´°¿ÚÒÑ´ò¿ªµÄÐÅÏ¢¡£È»ºóÔÚÖ´ÐÐ ui.closeAll()
ʱ£¬¿ØÖÆ̨»áÊä³öÿ¸ö´°¿ÚÒѹرյÄÐÅÏ¢£¬×îºóÊä³öËùÓд°¿ÚÒѹرյÄÐÅÏ¢¡£Èç¹ûÄãûÓп´µ½´ò¿ª´°ÌåµÄÊä³ö£¬¿ÉÄÜÊÇ¿ØÖÆ̨ûÓÐÏÔʾÕâЩÐÅÏ¢£¬»òÕßÄãÔÚÖ´ÐдúÂëʱûÓÐ×¢Òâµ½ÕâЩÊä³ö¡£
µÚËĸö£ºHUI½»»¥Ä£¿é¹Ø±Õ
// ¶¨Òå HUI Ä£¿é
var HUI = {
name: "HUI½»»¥Ä£¿é",
isOpen: false, // Ä£¿éÊÇ·ñ¿ªÆô
// ´ò¿ªÄ£¿é
open: function() {
this.isOpen = true;
console.log(this.name + " ÒÑ´ò¿ª");
// ÕâÀïÓ¦¸ÃÊǵ÷ÓÃÏÔʾ´°¿ÚµÄÂß¼
// ±ÈÈç¿ÉÄÜÊÇʹÓÃij¸ö¿ò¼ÜµÄÏÔʾ´°¿Ú·½·¨
},
// ¹Ø±ÕÄ£¿é
close: function() {
if (this.isOpen) {
this.isOpen = false;
console.log(this.name + " ÒѹرÕ");
// ÕâÀïÓ¦¸ÃÊǵ÷ÓÃÒþ²Ø´°¿ÚµÄÂß¼
// ±ÈÈç¿ÉÄÜÊÇʹÓÃij¸ö¿ò¼ÜµÄÒþ²Ø´°¿Ú·½·¨
} else {
console.log(this.name + " ÒÑ´¦ÓڹرÕ״̬");
}
}
};
// ʾÀý£º´ò¿ª HUI Ä£¿é
HUI.open(); // ´ò¿ª´°¿Ú
// ʾÀý£º¹Ø±Õ HUI Ä£¿é
HUI.close(); // ¹Ø±Õ´°¿Ú
Õâ¶Î´úÂëµÄÖ÷ҪĿµÄÊÇ´´½¨Ò»¸ö¼òµ¥µÄ¹ÜÀíÄ£¿é£¬ÒÔ±ã¿ØÖÆÆä´ò¿ªºÍ¹Ø±Õ״̬¡£open ºÍ close ·½·¨·Ö±ðÓÃÓÚ¹ÜÀíÄ£¿éÏÔʾµÄÂß¼¡£ËäÈ»´úÂëÖеÄÏÔʾºÍÒþ²ØÂß¼ÐèÒª¸ù¾Ýʵ¼ÊʹÓõĿò¼Ü»òÉ豸ÓèÒÔʵÏÖ£¬µ«»ù±¾µÄÂß¼½á¹¹ÒѾÍê³É¡£ÕâʹµÃ´úÂëÔÚ×éÖ¯·½Ê½ÉÏÇåÎú£¬²¢ÌṩÁËÒ»¸öλÓÚ½«À´¿ÉÄÜÌí¼Ó½çÃ湦ÄܵĻù´¡¡£
µÚËĸö£º JsWebView Ä£¿éä¯ÀÀÆ÷¹Ø±Õ
// ¶¨Òå JsWebView Àà
function JsWebView(url) {
this.url = url;
this.isOpen = false;
// ´ò¿ª WebView
this.open = function() {
this.isOpen = true;
console.log("WebView ´ò¿ª£¬¼ÓÔØ URL: " + this.url);
// ÕâÀï¿ÉÒÔÌí¼Óʵ¼Ê´ò¿ª WebView µÄ´úÂë
};
// ¹Ø±Õ WebView
this.close = function() {
if (this.isOpen) {
this.isOpen = false;
console.log("WebView ÒѹرÕ");
// ÕâÀï¿ÉÒÔÌí¼Óʵ¼Ê¹Ø±Õ WebView µÄ´úÂë
} else {
console.log("WebView ÒÑ´¦ÓڹرÕ״̬");
}
};
}
// ´´½¨ JsWebView ʵÀý
var myWebView = new JsWebView("https://example.com");
// ´ò¿ª WebView
myWebView.open();
// ¹Ø±Õ WebView
myWebView.close();
¶¨Òå JsWebView Àà
function JsWebView(url)£º¹¹Ô캯Êý½ÓÊÜÒ»¸ö URL£¬ÓÃÓÚ¼ÓÔØÄÚÈÝ¡£
this.url£º´æ´¢´«ÈëµÄ URL¡£
this.isOpen£º¸ú×Ù WebView µÄ´ò¿ª×´Ì¬£¬³õʼֵΪ false¡£
´ò¿ª WebView
this.open = function()£ºÒ»¸ö·½·¨ÓÃÓÚ´ò¿ª WebView¡£
½« isOpen ÉèÖÃΪ true£¬²¢Êä³ö WebView ´ò¿ªºÍ¼ÓÔØµÄ URL ÐÅÏ¢¡£
¿ÉÔÚ´Ë´¦²åÈëʵ¼Ê´ò¿ª WebView µÄ´úÂë¡£
¹Ø±Õ WebView
this.close = function()£ºÒ»¸ö·½·¨ÓÃÓÚ¹Ø±Õ WebView¡£
¼ì²é isOpen ״̬£¬Èç¹û WebView ´ò¿ª£¬ÔòÉèÖÃΪ false ²¢Êä³öÒѹرյÄÐÅÏ¢£»Èç¹ûÒѹرգ¬ÔòÊä³öÒÑ´¦ÓڹرÕ״̬µÄÐÅÏ¢¡£
¿ÉÔÚ´Ë´¦²åÈëʵ¼Ê¹Ø±Õ WebView µÄ´úÂë¡£
´´½¨ÊµÀý²¢µ÷ÓÃ
var myWebView = new JsWebView(¡°https://example.com")£º´´½¨ JsWebView µÄʵÀý£¬²¢´«ÈëÒ»¸ö URL¡£
µ÷Óà open() ·½·¨´ò¿ª WebView£¬²¢µ÷Óà close() ·½·¨¹Ø±Õ WebView¡£
¸ÃʾÀýչʾÁËÈçºÎ´´½¨Ò»¸ö¼òµ¥µÄ JsWebView À࣬Äܹ»´ò¿ªºÍ¹Ø±Õ WebView¡£Äú¿ÉÒÔ½«Æä×÷Ϊ»ù´¡£¬¸ù¾Ý¾ßÌåÐèÇóÀ©Õ¹»òÕß¼¯³Éµ½ÆäËû JAVA/JavaScript ´úÂëÖÐÈ¥¡£ÔÚʵ¼ÊÓ¦ÓÃÖУ¬¡±´ò¿ª¡± ºÍ ¡°¹Ø±Õ¡± µÄÂß¼»á¸ù¾ÝʹÓõÄƽ̨½øÐÐʵ¼Êʵʩ¡£
µÚÎå¸ö£º ¹Ø±ÕÈÕÖ¾´°¿Ú
// ¼ÙÉè logWindow ¶ÔÏóÒѾ´æÔÚ£¬²¢°üº¬ÓÐ close ·½·¨
var logWindow = {
isOpen: false,
open: function() {
this.isOpen = true;
console.log("ÈÕÖ¾´°¿ÚÒÑ´ò¿ª");
},
close: function() {
if (this.isOpen) {
this.isOpen = false;
console.log("ÈÕÖ¾´°¿ÚÒѹرÕ");
} else {
console.log("ÈÕÖ¾´°¿ÚÒÑ´¦ÓڹرÕ״̬");
}
}
};
// ʹÓÃʾÀý
logWindow.open(); // ´ò¿ªÈÕÖ¾´°¿Ú
logWindow.close(); // ¹Ø±ÕÈÕÖ¾´°¿Ú
logWindow.close(); // ³¢ÊÔÔٴιرÕ
µÚÁù¸ö£ºÊÍ·Å YOLO
¸´ÖÆ// OCR ²¿·Ö
let img = screen.screenShotFull();
let ocrres = img.paddleOCR(640, [0, 0, 1, 1]);
printl(ocrres); // ´òÓ¡ OCR ½á¹û
// ²éÕÒº¬ÓÐ "qq" µÄÎÄ×ÖÄ¿±ê
var qqrect = ocrres.findIncludeText("qq");
if (qqrect) {
qqrect.hidClick(); // µã»÷ÕÒµ½µÄÄ¿±ê
} else {
printl("ûÓÐÕÒµ½°üº¬ 'qq' µÄÎı¾"); // ÌáʾδÕÒµ½
}
// YOLO ²¿·Ö
// ³õʼ»¯ yolov5
var yolo = new yoloV5();
// ¼ÓÔزå¼þÎļþ¼ÐÀïµÄʶ±ð¿â
var labelPath = project.getResourcesPath() + 'close.txt';
var paramPath = project.getResourcesPath() + 'close.param';
var binPath = project.getResourcesPath() + 'close.bin';
// ¼ÓÔØÄ£ÐÍ
var model = yolo.loadModel(labelPath, paramPath, binPath, 4, false);
if (model != null) {
printl('Ä£ÐͼÓÔØʧ°Ü');
} else {
var img = screen.screenShotFull(); // ÔٴνØͼ
var res = yolo.detectPercent(img, [0, 0, 1, 1], 0.4, 0.45, 640);
printl(res); // ´òÓ¡¼ì²â½á¹û
if (res != null && res.length > 0) {
// ÎÞÕÏ°µã»÷
// res[0].click(); // Èç¹ûÓмì²â½á¹û£¬¿ÉÒÔµã»÷µÚÒ»¸ö
} else {
printl("ûÓмì²âµ½Ä¿±ê"); // Ìáʾδ¼ì²âµ½
}
}
// ÊÍ·Å YOLO
yolo.Close();
OCR£¨¹âѧ×Ö·ûʶ±ð£©ºÍ YOLO£¨You Only Look Once£¬¶ÔÏó¼ì²âËã·¨£©À´´¦ÀíͼÏñ£¬²éÕÒÎı¾ºÍÄ¿±ê¡£ÒÔÏÂÊÇ´úÂëµÄÖð²½½âÊÍ£º
1. OCR ²¿·Ö
let img = screen.screenShotFull(); // ½ØÈ¡Õû¸öÆÁÄ»
let ocrres = img.paddleOCR(640, [0, 0, 1, 1]); // ʹÓà PaddleOCR ½øÐÐÎÄ×Öʶ±ð
printl(ocrres); // ´òÓ¡ OCR ½á¹û
screen.screenShotFull()
£º½ØÈ¡µ±Ç°ÆÁÄ»µÄÍêÕûͼÏñ²¢¸³Öµ¸ø±äÁ¿img
¡£img.paddleOCR(640, [0, 0, 1, 1])
£ºÍ¨¹ý PaddleOCR ¶Ô½ØÈ¡µÄͼƬ½øÐÐÎÄ×Öʶ±ð¡£640
ÊÇʶ±ðͼÏñµÄ³ß´ç£¬[0, 0, 1, 1]
ÊÇʶ±ðÇøÓòµÄ²ÎÊý¡£printl(ocrres)
£º½«Ê¶±ð½á¹û´òÓ¡µ½¿ØÖÆ̨£¬ÒÔ±ã²é¿´Ê¶±ðµÄÎı¾¡£// ²éÕÒº¬ÓÐ ¡°qq¡± µÄÎÄ×ÖÄ¿±ê
var qqrect = ocrres.findIncludeText(¡°qq¡±);
if (qqrect) {qqrect.hidClick(); // µã»÷ÕÒµ½µÄÄ¿±ê
} else {
printl("ûÓÐÕÒµ½°üº¬ 'qq' µÄÎı¾"); // ÌáʾδÕÒµ½
}
ocrres.findIncludeText("qq")
£ºÔÚ OCR ½á¹ûÖвéÕÒ°üº¬×Ö·û ¡°qq¡± µÄÎı¾£¬·µ»ØÏàÓ¦µÄÎı¾¿òÇøÓò¡£if (qqrect)
£º¼ì²éÕÒµ½µÄÄ¿±ê¿òqqrect
ÊÇ·ñ´æÔÚ¡£- Èç¹û´æÔÚ£¬Ôòµ÷ÓÃ
hidClick()
·½·¨Ä£Äâµã»÷¸ÃÎı¾Ä¿±ê¡£ - Èç¹û²»´æÔÚ£¬ÔòÊä³ö¡±Ã»ÓÐÕÒµ½°üº¬ ¡®qq¡¯ µÄÎı¾¡±µÄÌáʾÐÅÏ¢¡£
- Èç¹û´æÔÚ£¬Ôòµ÷ÓÃ
2. YOLO ²¿·Ö
// ³õʼ»¯ yolov5
var yolo = new yoloV5(); // ´´½¨ YOLO ʵÀý
// ¼ÓÔزå¼þÎļþ¼ÐÀïµÄʶ±ð¿â
var labelPath = project.getResourcesPath() + 'close.txt';
var paramPath = project.getResourcesPath() + 'close.param';
var binPath = project.getResourcesPath() + 'close.bin';
new yoloV5()
£º´´½¨Ò»¸öÐ嵀 YOLO ʵÀý£¬ÓÃÓÚ¶ÔÏó¼ì²â¡£¼ÓÔØʶ±ð¿â£ºÍ¨¹ý
getResourcesPath()
·½·¨»ñÈ¡Ä£ÐÍÎļþµÄ·¾¶£¬²¢½«±êÇ©¡¢²ÎÊýºÍ¶þ½øÖÆÎļþ·¾¶·ÖÅä¸ølabelPath
¡¢paramPath
ºÍbinPath
±äÁ¿¡£// ¼ÓÔØÄ£ÐÍ
var model = yolo.loadModel(labelPath, paramPath, binPath, 4, false);if (model != null) {
printl('Ä£ÐͼÓÔØʧ°Ü'); // Èç¹û model ²»Îª null£¬±íʾ¼ÓÔØʧ°Ü
} else {
var img = screen.screenShotFull(); // ÔٴνØͼ var res = yolo.detectPercent(img, [0, 0, 1, 1], 0.4, 0.45, 640); // ½øÐжÔÏó¼ì²â printl(res); // ´òÓ¡¼ì²â½á¹û if (res != null && res.length > 0) { // ÎÞÕÏ°µã»÷ // res[0].click(); // Èç¹ûÓмì²â½á¹û£¬¿ÉÒÔµã»÷µÚÒ»¸ö } else { printl("ûÓмì²âµ½Ä¿±ê"); // Ìáʾδ¼ì²âµ½ }
}
yolo.loadModel(...)
£º¼ÓÔØ YOLO Ä£ÐÍ£¬Ê¹ÓÃ֮ǰ׼±¸µÄ±êÇ©¡¢²ÎÊýºÍ¶þ½øÖÆÎļþ¡£if (model != null)
£º¼ì²éÄ£ÐͼÓÔØÊÇ·ñ³É¹¦¡£Èç¹û·µ»ØµÄmodel
²»Îªnull
£¬ÔòÊä³ö¡±Ä£ÐͼÓÔØʧ°Ü¡±¡£screen.screenShotFull()
£ºÔٴνØÈ¡ÆÁÄ»½øÐжÔÏó¼ì²â¡£yolo.detectPercent(...)
£ºÔÚÖ¸¶¨ÇøÓòÄÚ½øÐжÔÏó¼ì²â£¬·µ»Ø¼ì²â½á¹û¡£printl(res)
£º´òÓ¡¼ì²â½á¹û¡£if (res != null && res.length > 0)
£º¼ì²é¼ì²â½á¹ûÊý×éÊÇ·ñÓÐÄÚÈÝ¡£- Èç¹û´æÔÚ¼ì²â½á¹û£¬×¢ÊͲ¿·ÖÌáµ½¿ÉÒÔµã»÷µÚÒ»¸öÄ¿±ê¡£
- Èç¹ûûÓмì²âµ½Ä¿±ê£¬Êä³ö¡±Ã»Óмì²âµ½Ä¿±ê¡±µÄÌáʾÐÅÏ¢¡£
3. ÊÍ·Å×ÊÔ´
// ÊÍ·Å YOLO
yolo.Close(); // ÊÍ·Å YOLO Ä£Ð͵Ä×ÊÔ´
yolo.Close()
£ºÊÍ·Å YOLO Ä£ÐÍÕ¼ÓõÄ×ÊÔ´£¬ÒÔÇåÀíÄÚ´æºÍÆäËûʹÓá£