|
|
AIWROKÈí¼þͼÏñ¶þÖµ»¯µÄ¸÷ÖÖ·½·¨ºÍÓ¦Óó¡¾°
- //🍎½»Á÷ QQ Ⱥ 711841924 Ⱥһ£¬Æ»¹ûÄÚ²âȺ£¬528816639
- //ÊÊÓñ¾ÎĵµES5ϵͳ°²×¿ JavaScriptÒýÇæRhino
- /**
- * ͼƬ¶þÖµ»¯Ê¾Àý(¼ò»¯°æ)
- * ¹¦ÄÜ˵Ã÷£ºÕ¹Ê¾ÔÚAIWROKÈí¼þÖÐʹÓÃOpenCV½øÐÐͼÏñ¶þÖµ»¯µÄ¸÷ÖÖ·½·¨ºÍÓ¦Óó¡¾°
- * ¶þÖµ»¯ÔÀí£º½«Í¼Ïñת»»ÎªÖ»ÓкںͰ×Á½ÖÖÑÕÉ«µÄ¹ý³Ì£¬³£ÓÃÓÚͼÏñÔ¤´¦Àí¡¢ÌØÕ÷ÌáÈ¡µÈ
- */
- /**
- * »ù±¾¶þÖµ»¯Ê¾Àý
- * @param {number} lowThreshold µÍãÐÖµ£¬µÍÓÚ´ËÖµµÄÏñËØ×ªÎªºÚÉ«
- * @param {number} highThreshold ¸ßãÐÖµ£¬¸ßÓÚ´ËÖµµÄÏñËØ×ªÎª°×É«
- * @returns {Object} °üº¬¶þÖµ»¯½á¹ûµÄ¶ÔÏó
- */
- function basicThresholdDemo(lowThreshold, highThreshold) {
- printl("Ö´Ðлù±¾¶þÖµ»¯Ê¾Àý...");
-
- // ÉèÖÃĬÈÏãÐÖµ
- lowThreshold = lowThreshold || 50;
- highThreshold = highThreshold || 150;
-
- // »ñÈ¡ÆÁÄ»³ß´ç
- var screenWidth = typeof screen !== 'undefined' && typeof screen.getScreenWidth === 'function' ?
- screen.getScreenWidth() : 1080;
- var screenHeight = typeof screen !== 'undefined' && typeof screen.getScreenHeight === 'function' ?
- screen.getScreenHeight() : 1920;
-
- // ½ØÍ¼²¢»ñÈ¡Mat¶ÔÏó
- var screenshot = screen.screenShotFull();
- var mat = screenshot.getMat();
-
- if (!mat) {
- return { error: true, message: "ÎÞ·¨»ñȡͼÏñMat¶ÔÏó" };
- }
-
- printl("Ôͼ´óС: " + screenshot.getWidth() + "x" + screenshot.getHeight());
- printl("ʹÓÃãÐÖµ: " + lowThreshold + " - " + highThreshold);
-
- // Ö´ÐжþÖµ»¯²Ù×÷
- opencv.threshold(mat, lowThreshold, highThreshold);
-
- // Êä³ö½á¹ûÐÅÏ¢
- printl("¶þÖµ»¯ºóMatÐÅÏ¢:");
- printl(mat);
-
- printl("»ù±¾¶þÖµ»¯Íê³É");
-
- return {
- error: false,
- mat: mat,
- message: "»ù±¾¶þÖµ»¯³É¹¦"
- };
- }
- /**
- * ÇøÓò¶þÖµ»¯Ê¾Àý
- * @param {number} x ÇøÓòÆðʼx×ø±ê
- * @param {number} y ÇøÓòÆðʼy×ø±ê
- * @param {number} width ÇøÓò¿í¶È
- * @param {number} height ÇøÓò¸ß¶È
- * @param {number} threshold ¶þÖµ»¯ãÐÖµ
- * @returns {Object} °üº¬¶þÖµ»¯½á¹ûµÄ¶ÔÏó
- */
- function regionThresholdDemo(x, y, width, height, threshold) {
- printl("Ö´ÐÐÇøÓò¶þÖµ»¯Ê¾Àý...");
-
- // »ñÈ¡ÆÁÄ»³ß´ç
- var screenWidth = typeof screen !== 'undefined' && typeof screen.getScreenWidth === 'function' ?
- screen.getScreenWidth() : 1080;
- var screenHeight = typeof screen !== 'undefined' && typeof screen.getScreenHeight === 'function' ?
- screen.getScreenHeight() : 1920;
-
- // ĬÈÏÖµÉèÖÃ
- x = x || 0;
- y = y || 0;
- width = width || Math.floor(screenWidth / 2);
- height = height || Math.floor(screenHeight / 2);
- threshold = threshold || 100;
-
- // È·±£ÇøÓò²ÎÊýÔÚÓÐЧ·¶Î§ÄÚ
- x = Math.max(0, x);
- y = Math.max(0, y);
- width = Math.min(screenWidth - x, width);
- height = Math.min(screenHeight - y, height);
-
- printl("ÇøÓò´óС: " + width + "x" + height);
- printl("ÇøÓòλÖÃ: (" + x + ", " + y + ")");
- printl("ʹÓÃãÐÖµ: " + threshold);
-
- // ½ØÍ¼
- var fullScreenshot = screen.screenShotFull();
- var fullMat = fullScreenshot.getMat();
-
- if (!fullMat) {
- return { error: true, message: "ÎÞ·¨»ñȡͼÏñMat¶ÔÏó" };
- }
-
- // ʹÓÃsubmat·½·¨ÌáÈ¡ÇøÓò¶ø²»ÊÇextractRegion
- var mat = fullMat.submat(y, y + height, x, x + width);
-
- if (!mat) {
- return { error: true, message: "ÎÞ·¨»ñÈ¡ÇøÓòͼÏñMat¶ÔÏó" };
- }
-
- // Êä³öÌáÈ¡µÄÇøÓòÐÅÏ¢
- printl("ÌáÈ¡ÇøÓòºóMatÐÅÏ¢:");
- printl(mat);
-
- // Ö´ÐжþÖµ»¯²Ù×÷
- opencv.threshold(mat, threshold, 255);
-
- // Êä³ö¶þÖµ»¯ºóµÄ½á¹û
- printl("ÇøÓò¶þÖµ»¯ºóMatÐÅÏ¢:");
- printl(mat);
-
- printl("ÇøÓò¶þÖµ»¯Íê³É");
-
- return {
- error: false,
- mat: mat,
- message: "ÇøÓò¶þÖµ»¯³É¹¦"
- };
- }
- /**
- * ¶àãÐÖµ¶Ô±È¶þÖµ»¯Ê¾Àý
- * չʾ²»Í¬ãÐÖµ¶Ô¶þÖµ»¯½á¹ûµÄÓ°Ïì
- */
- function multiThresholdComparison() {
- printl("Ö´ÐжàãÐÖµ¶Ô±È¶þÖµ»¯Ê¾Àý...");
-
- // »ñÈ¡ÆÁÄ»³ß´ç
- var screenWidth = typeof screen !== 'undefined' && typeof screen.getScreenWidth === 'function' ?
- screen.getScreenWidth() : 1080;
- var screenHeight = typeof screen !== 'undefined' && typeof screen.getScreenHeight === 'function' ?
- screen.getScreenHeight() : 1920;
-
- // ½ØÍ¼²¢»ñÈ¡ÔʼMat¶ÔÏó
- var screenshot = screen.screenShotFull();
- var originalMat = screenshot.getMat();
-
- if (!originalMat) {
- printl("ÎÞ·¨»ñȡͼÏñMat¶ÔÏó");
- return false;
- }
-
- // ¶¨ÒåÒª²âÊÔµÄãÐÖµ×éºÏ
- var thresholdSets = [
- { low: 30, high: 100, name: "µÍãÐÖµ" },
- { low: 80, high: 180, name: "ÖеÈãÐÖµ" },
- { low: 120, high: 220, name: "¸ßãÐÖµ" }
- ];
-
- // ¶Ôÿ¸öãÐÖµ×éºÏÖ´ÐжþÖµ»¯
- for (var i = 0; i < thresholdSets.length; i++) {
- var set = thresholdSets[i];
- printl("\n²âÊÔ" + set.name + ": µÍ=" + set.low + ", ¸ß=" + set.high);
-
- // ´´½¨ÔʼͼÏñµÄ¸±±¾ÒÔ±ÜÃâÐÞ¸ÄÔͼ
- var matCopy = originalMat.clone();
-
- // Ö´ÐжþÖµ»¯
- opencv.threshold(matCopy, set.low, set.high);
-
- // Êä³ö½á¹ûÐÅÏ¢
- printl(set.name + "¶þÖµ»¯ºóMatÐÅÏ¢:");
- printl(matCopy);
-
- // ¿ÉÒÔÔÚÕâÀォ½á¹û±£´æ»òÏÔʾ
- printl(set.name + "¶þÖµ»¯Íê³É");
- }
-
- printl("\n¶àãÐÖµ¶Ô±ÈÍê³É");
- return true;
- }
- /**
- * »Ò¶Èת»»ºó¶þÖµ»¯Ê¾Àý
- * ÏȽ«Í¼ÏñתΪ»Ò¶È£¬ÔÙ½øÐжþÖµ»¯´¦Àí
- */
- function grayThenThresholdDemo() {
- printl("Ö´ÐлҶÈת»»ºó¶þÖµ»¯Ê¾Àý...");
-
- // »ñÈ¡ÆÁÄ»³ß´ç
- var screenWidth = typeof screen !== 'undefined' && typeof screen.getScreenWidth === 'function' ?
- screen.getScreenWidth() : 1080;
- var screenHeight = typeof screen !== 'undefined' && typeof screen.getScreenHeight === 'function' ?
- screen.getScreenHeight() : 1920;
-
- // ½ØÍ¼
- var screenshot = screen.screenShotFull();
- var mat = screenshot.getMat();
-
- if (!mat) {
- return { error: true, message: "ÎÞ·¨»ñȡͼÏñMat¶ÔÏó" };
- }
-
- // ÏÈת»»Îª»Ò¶Èͼ
- printl("ת»»Îª»Ò¶Èͼ...");
- opencv.toGray(mat);
-
- // Êä³ö»Ò¶ÈͼÐÅÏ¢
- printl("»Ò¶ÈͼMatÐÅÏ¢:");
- printl(mat);
-
- // ÔÙ½øÐжþÖµ»¯
- printl("Ö´ÐжþÖµ»¯...");
- opencv.threshold(mat, 80, 200);
-
- // Êä³ö¶þÖµ»¯ºóµÄ½á¹û
- printl("»Ò¶Èºó¶þÖµ»¯MatÐÅÏ¢:");
- printl(mat);
-
- printl("»Ò¶Èºó¶þÖµ»¯Íê³É");
-
- return {
- error: false,
- mat: mat,
- message: "»Ò¶Èת»»ºó¶þÖµ»¯³É¹¦"
- };
- }
- /**
- * Ó¦Ó󡾰ʾÀý£º¶þÖµ»¯ºó½øÐÐÂÖÀª¼ì²â
- * @param {number} threshold ¶þÖµ»¯ãÐÖµ
- */
- function thresholdForContourDetection(threshold) {
- printl("Ö´ÐжþÖµ»¯ºóÂÖÀª¼ì²âʾÀý...");
-
- threshold = threshold || 100;
-
- // »ñÈ¡ÆÁÄ»³ß´ç
- var screenWidth = typeof screen !== 'undefined' && typeof screen.getScreenWidth === 'function' ?
- screen.getScreenWidth() : 1080;
- var screenHeight = typeof screen !== 'undefined' && typeof screen.getScreenHeight === 'function' ?
- screen.getScreenHeight() : 1920;
-
- // ½ØÍ¼²¢×ª»»Îª»Ò¶È
- var screenshot = screen.screenShotFull();
- var mat = screenshot.getMat();
-
- if (!mat) {
- printl("ÎÞ·¨»ñȡͼÏñMat¶ÔÏó");
- return false;
- }
-
- // ת»»Îª»Ò¶Èͼ
- opencv.toGray(mat);
-
- // Êä³ö»Ò¶ÈͼÐÅÏ¢
- printl("»Ò¶ÈͼMatÐÅÏ¢:");
- printl(mat);
-
- // ¶þÖµ»¯
- opencv.threshold(mat, threshold, 255);
-
- // Êä³ö¶þÖµ»¯ºóµÄ½á¹û
- printl("¶þÖµ»¯ºóMatÐÅÏ¢:");
- printl(mat);
-
- // ½øÐÐÂÖÀª¼ì²â
- printl("½øÐÐÂÖÀª¼ì²â...");
- var contours = opencv.getContours(mat);
-
- if (contours && contours.length > 0) {
- printl("ÕÒµ½ " + contours.length + " ¸öÂÖÀª");
-
- // ¿ÉÒÔÔÚÕâÀï¶ÔÂÖÀª½øÐнøÒ»²½´¦Àí
- for (var i = 0; i < Math.min(5, contours.length); i++) { // Ö»ÏÔʾǰ5¸öÂÖÀªÐÅÏ¢
- var contour = contours[i];
- printl("ÂÖÀª " + (i+1) + ": λÖÃ(" + contour.x + "," + contour.y + "), ´óС " + contour.width + "x" + contour.height);
- }
- } else {
- printl("δÕÒµ½ÂÖÀª");
- }
-
- printl("ÂÖÀª¼ì²âʾÀýÍê³É");
- return true;
- }
- /**
- * Ó¦Ó󡾰ʾÀý£º¶þÖµ»¯ºó½øÐÐOCRʶ±ð
- * ¶ÔÎÄ×ÖÇøÓò½øÐжþÖµ»¯ÒÔÌá¸ßOCRʶ±ðÂÊ
- * @param {number} x ÎÄ×ÖÇøÓòx×ø±ê
- * @param {number} y ÎÄ×ÖÇøÓòy×ø±ê
- * @param {number} width ÎÄ×ÖÇøÓò¿í¶È
- * @param {number} height ÎÄ×ÖÇøÓò¸ß¶È
- */
- function thresholdForOCRDemo(x, y, width, height) {
- printl("Ö´ÐжþÖµ»¯ºóOCRʶ±ðʾÀý...");
-
- // »ñÈ¡ÆÁÄ»³ß´ç
- var screenWidth = typeof screen !== 'undefined' && typeof screen.getScreenWidth === 'function' ?
- screen.getScreenWidth() : 1080;
- var screenHeight = typeof screen !== 'undefined' && typeof screen.getScreenHeight === 'function' ?
- screen.getScreenHeight() : 1920;
-
- // ĬÈÏÖµÉèÖà - ʹÓÃÆÁÄ»ÖÐÐÄÇøÓò
- x = x || Math.floor(screenWidth / 4);
- y = y || Math.floor(screenHeight / 4);
- width = width || Math.floor(screenWidth / 2);
- height = height || Math.floor(screenHeight / 4);
-
- // È·±£ÇøÓò²ÎÊýÔÚÓÐЧ·¶Î§ÄÚ
- x = Math.max(0, x);
- y = Math.max(0, y);
- width = Math.min(screenWidth - x, width);
- height = Math.min(screenHeight - y, height);
-
- printl("ÎÄ×ÖÇøÓò: (" + x + "," + y + ") " + width + "x" + height);
-
- // ½ØÍ¼
- var fullScreenshot = screen.screenShotFull();
- var fullMat = fullScreenshot.getMat();
-
- if (!fullMat) {
- printl("ÎÞ·¨»ñȡͼÏñMat¶ÔÏó");
- return false;
- }
-
- // ʹÓÃsubmat·½·¨ÌáÈ¡ÇøÓò
- var mat = fullMat.submat(y, y + height, x, x + width);
-
- if (!mat) {
- printl("ÎÞ·¨»ñÈ¡ÎÄ×ÖÇøÓòͼÏñ");
- return false;
- }
-
- printl("ÌáÈ¡µÄÎÄ×ÖÇøÓòMatÐÅÏ¢:");
- printl(mat);
-
- printl("ÎÄ×ÖÇøÓò: (" + x + "," + y + ") " + width + "x" + height);
-
- // Ô¤´¦Àí£º×ª»»Îª»Ò¶È
- opencv.toGray(mat);
-
- // Êä³ö»Ò¶ÈͼÐÅÏ¢
- printl("ÎÄ×ÖÇøÓò»Ò¶ÈͼÐÅÏ¢:");
- printl(mat);
-
- // ¶þÖµ»¯ - ÎÄ×Öʶ±ðͨ³£ÐèÒª½Ï¸ßµÄãÐÖµÀ´Í»³öÎÄ×Ö
- opencv.threshold(mat, 100, 200);
-
- // Êä³ö¶þÖµ»¯ºóµÄ½á¹û
- printl("ÎÄ×ÖÇøÓò¶þÖµ»¯ºóMatÐÅÏ¢:");
- printl(mat);
-
- printl("¶þÖµ»¯Ô¤´¦ÀíÍê³É£¬×¼±¸OCRʶ±ð");
-
- // ×¢Ò⣺ʵ¼ÊʹÓÃÖУ¬ÕâÀïÓ¦¸Ãµ÷ÓÃAIWROKµÄOCR¹¦ÄÜ
- printl("Ìáʾ£ºÔÚʵ¼ÊÓ¦ÓÃÖУ¬ÕâÀïÓ¦µ÷ÓÃocr.recognize()»òÆäËûOCR·½·¨");
-
- return true;
- }
- /**
- * ×ÔÊÊÓ¦ãÐÖµ¶þÖµ»¯Ä£Äâ
- * Ä£Äâ×ÔÊÊÓ¦ãÐÖµµÄЧ¹û£¬Í¨¹ý¶ÔͼÏñ²»Í¬ÇøÓòʹÓò»Í¬ãÐÖµ
- * @param {number} blockSize ¿é´óС
- */
- function adaptiveThresholdSimulation(blockSize) {
- printl("Ö´ÐÐ×ÔÊÊÓ¦ãÐÖµ¶þÖµ»¯Ä£Äâ...");
-
- blockSize = blockSize || 4; // ½«Í¼Ïñ·Ö³ÉblockSize x blockSize¿é
-
- // »ñÈ¡ÆÁÄ»³ß´ç
- var screenWidth = typeof screen !== 'undefined' && typeof screen.getScreenWidth === 'function' ?
- screen.getScreenWidth() : 1080;
- var screenHeight = typeof screen !== 'undefined' && typeof screen.getScreenHeight === 'function' ?
- screen.getScreenHeight() : 1920;
-
- var screenshot = screen.screenShotFull();
- var mat = screenshot.getMat();
-
- if (!mat) {
- printl("ÎÞ·¨»ñȡͼÏñMat¶ÔÏó");
- return false;
- }
-
- var imgWidth = screenshot.getWidth();
- var imgHeight = screenshot.getHeight();
-
- // ¼ÆËãÿ¸ö¿éµÄ´óС
- var blockW = Math.floor(imgWidth / blockSize);
- var blockH = Math.floor(imgHeight / blockSize);
-
- printl("ͼÏñ·Ö¸îΪ " + blockSize + "x" + blockSize + " ¿é£¬Ã¿¿é´óСԼ " + blockW + "x" + blockH);
-
- // ת»»Îª»Ò¶Èͼ
- opencv.toGray(mat);
-
- // Êä³ö»Ò¶ÈͼÐÅÏ¢
- printl("ÕûÌå»Ò¶ÈͼÐÅÏ¢:");
- printl(mat);
-
- // ¶Ôÿ¸ö¿éʹÓò»Í¬µÄãÐÖµ£¨ÕâÀïʹÓüòµ¥µÄËæ»úãÐֵģÄâ×ÔÊÊӦЧ¹û£©
- for (var i = 0; i < blockSize; i++) {
- for (var j = 0; j < blockSize; j++) {
- // ¼ÆËã¿éµÄ×ø±ê
- var blockX = i * blockW;
- var blockY = j * blockH;
- var currentBlockW = (i === blockSize - 1) ? imgWidth - blockX : blockW;
- var currentBlockH = (j === blockSize - 1) ? imgHeight - blockY : blockH;
-
- // È·±£ÇøÓò²ÎÊýÓÐЧ
- currentBlockW = Math.min(currentBlockW, imgWidth - blockX);
- currentBlockH = Math.min(currentBlockH, imgHeight - blockY);
-
- // Ϊÿ¸ö¿éÉú³ÉÒ»¸öËæ»úãÐÖµ£¨ÔÚÒ»¶¨·¶Î§ÄÚ£©
- var blockThreshold = 80 + Math.floor(Math.random() * 60);
-
- // ʹÓÃsubmat·½·¨ÌáÈ¡ÇøÓò
- if (blockY + currentBlockH <= imgHeight && blockX + currentBlockW <= imgWidth) {
- var blockMat = mat.submat(blockY, blockY + currentBlockH, blockX, blockX + currentBlockW);
-
- // Êä³ö¿éÐÅÏ¢
- printl("´¦Àí¿é(" + i + "," + j + ")£¬×ø±ê:(" + blockX + "," + blockY + ")£¬´óС:" + currentBlockW + "x" + currentBlockH);
-
- // ¶Ô¿é½øÐжþÖµ»¯
- opencv.threshold(blockMat, blockThreshold, 200);
-
- // Êä³ö¿é¶þÖµ»¯ºóµÄ½á¹û
- printl("¿é(" + i + "," + j + ")¶þÖµ»¯ºó:");
- printl(blockMat);
- }
- }
- }
-
- printl("×ÔÊÊÓ¦ãÐֵģÄâÍê³É£¬×îÖÕMatÐÅÏ¢:");
- printl(mat);
-
- return true;
- }
- /**
- * Ö÷º¯Êý£ºÔËÐÐËùÓжþÖµ»¯Ê¾Àý
- */
- function runAllThresholdDemos() {
- printl("==================================================");
- printl(" ͼƬ¶þÖµ»¯Ê¾Àý¼¯");
- printl("==================================================\n");
-
- // ¼ì²é»·¾³
- if (typeof opencv === 'undefined') {
- printl("´íÎó: δÕÒµ½OpenCVÄ£¿é£¬ÇëÈ·±£ÔÚAIWROK»·¾³ÖÐÔËÐÐ");
- return;
- }
-
- // »ñÈ¡ÆÁÄ»³ß´ç
- var screenWidth = typeof screen !== 'undefined' && typeof screen.getScreenWidth === 'function' ?
- screen.getScreenWidth() : 1080;
- var screenHeight = typeof screen !== 'undefined' && typeof screen.getScreenHeight === 'function' ?
- screen.getScreenHeight() : 1920;
-
- printl("µ±Ç°ÆÁÄ»³ß´ç: " + screenWidth + "x" + screenHeight);
-
- // 1. »ù±¾¶þÖµ»¯Ê¾Àý
- printl("1. »ù±¾¶þÖµ»¯Ê¾Àý");
- basicThresholdDemo(50, 150);
- printl("----------------------------------------\n");
-
- // 2. ÇøÓò¶þÖµ»¯Ê¾Àý
- printl("2. ÇøÓò¶þÖµ»¯Ê¾Àý");
- // ʹÓÃÆÁÄ»ÖÐÐĵÄÒ»¸öÇøÓò
- var regionX = Math.floor(screenWidth / 4);
- var regionY = Math.floor(screenHeight / 4);
- var regionWidth = Math.floor(screenWidth / 2);
- var regionHeight = Math.floor(screenHeight / 3);
- regionThresholdDemo(regionX, regionY, regionWidth, regionHeight, 100);
- printl("----------------------------------------\n");
-
- safeSleep(1000); // Ìí¼ÓÑÓ³Ù£¬±ÜÃâÁ¬Ðø²Ù×÷¹ý¿ì
-
- // 3. ¶àãÐÖµ¶Ô±È
- printl("3. ¶àãÐÖµ¶Ô±ÈʾÀý");
- multiThresholdComparison();
- printl("----------------------------------------\n");
-
- // 4. »Ò¶Èºó¶þÖµ»¯
- printl("4. »Ò¶Èת»»ºó¶þÖµ»¯Ê¾Àý");
- grayThenThresholdDemo();
- printl("----------------------------------------\n");
-
- safeSleep(1000); // Ìí¼ÓÑÓ³Ù
-
- // 5. ¶þÖµ»¯ºóÂÖÀª¼ì²â
- printl("5. ¶þÖµ»¯ºóÂÖÀª¼ì²âʾÀý");
- thresholdForContourDetection(100);
- printl("----------------------------------------\n");
-
- safeSleep(1000); // Ìí¼ÓÑÓ³Ù
-
- // 6. ¶þÖµ»¯ºóOCRʾÀý
- printl("6. ¶þÖµ»¯ºóOCRʶ±ðʾÀý");
- thresholdForOCRDemo(Math.floor(screenWidth / 4), Math.floor(screenHeight / 3), Math.floor(screenWidth / 2), Math.floor(screenHeight / 4));
- printl("----------------------------------------\n");
-
- safeSleep(1000); // Ìí¼ÓÑÓ³Ù
-
- // 7. ×ÔÊÊÓ¦ãÐֵģÄâ
- printl("7. ×ÔÊÊÓ¦ãÐÖµ¶þÖµ»¯Ä£Äâ");
- adaptiveThresholdSimulation(4);
- printl("----------------------------------------\n");
-
- printl("ËùÓжþÖµ»¯Ê¾ÀýÖ´ÐÐÍê³É£¡");
- }
- /**
- * ¹¤¾ßº¯Êý£º°²È«ÑÓ³Ù
- * @param {number} ms ÑÓ³ÙºÁÃëÊý
- */
- function safeSleep(ms) {
- if (typeof sleep !== 'undefined' && sleep.millisecond) {
- sleep.millisecond(ms);
- } else if (typeof java !== 'undefined') {
- java.lang.Thread.sleep(ms);
- }
- }
- /**
- * ¶þÖµ»¯¹¤¾ßÀà - Ìṩ±ã½ÝµÄ¶þÖµ»¯·½·¨
- */
- var ThresholdUtils = {
- /**
- * ¿ìËÙ¶þÖµ»¯Í¼Ïñ
- * @param {Object} options ÅäÖÃÑ¡Ïî
- * @returns {Object} ¶þÖµ»¯½á¹û
- */
- quickThreshold: function(options) {
- options = options || {};
-
- // »ñÈ¡ÆÁÄ»³ß´ç
- var screenWidth = typeof screen !== 'undefined' && typeof screen.getScreenWidth === 'function' ?
- screen.getScreenWidth() : 1080;
- var screenHeight = typeof screen !== 'undefined' && typeof screen.getScreenHeight === 'function' ?
- screen.getScreenHeight() : 1920;
-
- var screenshot = options.image || screen.screenShotFull();
- var mat = screenshot.getMat();
-
- if (options.toGray !== false) {
- opencv.toGray(mat);
- }
-
- opencv.threshold(
- mat,
- options.lowThreshold || 80,
- options.highThreshold || 200
- );
-
- // Êä³ö½á¹ûÐÅÏ¢
- printl("¿ìËÙ¶þÖµ»¯½á¹û:");
- printl(mat);
-
- return {
- success: true,
- mat: mat
- };
- },
-
- /**
- * ´¦ÀíÎÄ×ÖͼÏñµÄ¶þÖµ»¯²ÎÊý
- * @returns {Object} ÊʺÏÎÄ×ֵĶþÖµ»¯²ÎÊý
- */
- getTextThresholdParams: function() {
- return {
- lowThreshold: 100,
- highThreshold: 220,
- toGray: true
- };
- },
-
- /**
- * ´¦ÀíͼÏñ±ßÔµµÄ¶þÖµ»¯²ÎÊý
- * @returns {Object} ÊʺϱßÔµ¼ì²âµÄ¶þÖµ»¯²ÎÊý
- */
- getEdgeThresholdParams: function() {
- return {
- lowThreshold: 50,
- highThreshold: 150,
- toGray: true
- };
- }
- };
- // Ö´ÐÐËùÓжþÖµ»¯Ê¾Àý
- runAllThresholdDemos();
¸´ÖÆ´úÂë
|
|