บทความนี้แบ่งปันโปรแกรมการจดจำรหัสการตรวจสอบภาพ Javase อย่างง่ายสำหรับการอ้างอิงของคุณ เนื้อหาเฉพาะมีดังนี้
ก่อนอื่นคุณควรลองชิมภาพแล้วขยายตัวอย่างสีเทานั่นคือเปลี่ยนเป็นขาวดำ
จากนั้นคุณสามารถใช้คลาสนี้เพื่อวิเคราะห์ไฟล์วัตถุ ฉันคิดว่าคลาสนี้ชัดเจนมากเกี่ยวกับวิธีการใช้งาน มันคือการย้ายตัวอย่างในแนวนอนจากซ้ายและปรับพิกัดไปยังตำแหน่งถัดไปหากตรงกับที่เหมาะสม
โปรแกรมนี้เขียนขึ้นกว่า 3 ปีที่ผ่านมา แต่หลังจากนั้นมันก็ไม่ได้เขียนในเชิงลึก การจดจำภาพเป็นสนามที่ลึกมากซึ่งต้องใช้ทักษะทางคณิตศาสตร์และความสามารถในการคิดอย่างลึกซึ้ง โปรแกรม Java ไม่มีประสิทธิภาพและไม่สามารถจดจำภาพที่ผิดรูปหรือยืดได้ อย่างไรก็ตามมันก็เพียงพอแล้วในยุคนั้น หากคุณมีรหัสการจดจำภาพโอเพ่นซอร์สที่ดีกว่าโปรดเขียนเพื่อสื่อสารเพื่อสื่อสาร :)
/*** เอ็นจิ้นการแยกวิเคราะห์ภาพเหมาะสำหรับการวิเคราะห์รหัสการตรวจสอบเว็บไซต์ * ก่อนอื่นต้องโหลดตัวอย่างตัวแยกวิเคราะห์จะสแกนในแนวนอนจากซ้ายไปขวาและจะบันทึกโดยอัตโนมัติหากพบในตัวอย่าง * แน่นอนโปรแกรมนี้ไม่เหมาะสำหรับตัวอย่างและไม่ซ้ำกันนั่นคือรูปภาพที่จะระบุถูกปรับขนาดหรือพิกัดจะเปลี่ยนหรือผิดรูป โปรแกรมนี้ไม่สามารถดำเนินการระบุตัวตนดังกล่าวได้ * หากสีเปลี่ยนไปในภาพมากโปรแกรมนี้อาจมีปัญหา แน่นอนคุณสามารถเลือกค่ามาตรฐานเป็นมาตรฐานสำหรับการแปลงเป็นเมทริกซ์ 0,1 * * ตัวอย่างการผลิต: โปรดแปลงตัวอย่างเป็นโหมดสีเทา เป็นการดีที่สุดที่จะมีเพียงสองสี แน่นอนถ้าคุณไม่แปลงฉันจะช่วยคุณแปลงด้วย * */นำเข้า java.awt.image; นำเข้า java.awt.image.bufferedimage; นำเข้า java.io.file; นำเข้า java.util.arraylist; นำเข้า java.util.iterator; นำเข้า java.util.list; นำเข้า Javax.imageio.imageio; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ // matrixed private byte [] [] targetColors; - - - ค่า [i] = string.valueof (i); } imageParser parse = imageParser ใหม่ (ไฟล์, ค่า); Long Start = System.currentTimeMillis (); ลอง {// แยกวิเคราะห์ภาพ System.out.println (parse.parsevalue ("d:/workspace/szxlientapp/res/validatenum")); sincetime ยาว = system.currenttimeMillis (); System.out.println ("เวลาที่ใช้ =" + (Sincetime - เริ่มต้น)); } catch (exception e) {e.printstacktrace (); - - - System.out.println ("ไฟล์ตัวอย่างไม่ตรงกับค่าตัวอย่าง! โปรดรีเซ็ต!"); กลับ; } switches = arrayList ใหม่ (filesLength); swatchevalues = arrayList ใหม่ (ค่าความยาว); int i = 0; ลอง {สำหรับ (; i <files.length; i ++) {switches.add (imagetomatrix (ไฟล์ [i])); swatchevalues.add (i, ค่า [i]); }} catch (exception e) {system.out.println (ไฟล์ [i] + "ไม่สามารถแยกวิเคราะห์ได้"); E.PrintStackTrace (); }}} Public ImageParser () {super (); ถ้า (swatches == null || swatchevalues == null) {system.out.println ("คุณยังไม่ได้โหลดตัวอย่างโปรดโหลดตัวอย่างก่อน!"); }} / *** การแยกวิเคราะห์ค่าของภาพ** @param parsefilepath* ให้เส้นทางรูปภาพ* @return ส่งคืนสตริง* @throws Exception* / Public String ParseEvalue (String ParseFilePath) โยนข้อยกเว้น TargetColors = imagetomatrix (parsefilepath); // printmatrix (TargetColors); ความสูง int = targetColors.length; int targetWidth = targetColors [0] .length; ความกว้าง int = 0; ตัววนซ้ำมัน = switches.iterator (); ในขณะที่ (it.hasnext ()) {byte [] [] bytes = (byte [] []) it.next (); int temple = bytes [0] .length; if (templen> width) width = templen; } // system.out.println ("maxWidth =" + ความกว้าง); // system.out.println ("maxHeight =" + ความสูง); int xtag = 0; ในขณะที่ ((xtag + ความกว้าง) <TargetWidth) {cout: {iterator itx = switches.iterator (); int i = 0; ในขณะที่ (itx.hasnext ()) {byte [] [] bytes = (byte [] []) itx.next (); ไบต์ [] [] temp = splitmatrix (TargetColors, xtag, 0, ความกว้าง, ความสูง); // system.out.println (i ++); if (ismatrixinbigmatrix (ไบต์, อุณหภูมิ)) {xtag += ความกว้าง; // system.out.println ("ใหม่ maxtrix:"); // printmatrix (อุณหภูมิ); result.append (swatchevalues.get (i)); ทำลายศาล; } i ++; } xtag ++; }} return result.toString (); } // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- bigmatrix * เมทริกซ์ขนาดใหญ่ * @return กลับมาจริงถ้ามันมีอยู่ */ ส่วนตัวบูลีนสุดท้าย ismatrixinbigmatrix (byte [] [] แหล่งที่มา, byte [] [] bigmatrix) {ถ้า (แหล่งที่มา == bigmatrix) กลับจริง; if (source == null || bigmatrix == null) return false; if (source.length> bigmatrix.length) return false; ลอง {สำหรับ (int i = 0; i <source.length; i ++) {ถ้า (แหล่งที่มา [i] .length> bigmatrix [i] .length) ส่งคืนเท็จ; }} catch (arrayIndExOfBoundSexception e) {return false; } int height = source.length; ความกว้าง int = แหล่งที่มา [0] .length; int x = 0, y = 0; int i = 0, j = 0; จำนวน int = 0; int comparecount = ความสูง * ความกว้าง; สำหรับ (; i <bigmatrix.length - ความสูง+1; i ++) {สำหรับ (j = 0; j <bigmatrix [i] .length - ความกว้าง+1; j ++) {cout: {x = 0; นับ = 0; สำหรับ (int k = i; k <ความสูง+i; k ++) {y = 0; สำหรับ (int l = j; l <width + j; l ++) {// system.out.println ("ไบต์ [" + x + "] [" + y + "]" // + "=" + แหล่งที่มา [x] [y] + "," + "อื่น ๆ if ((แหล่งที่มา [x] [y] & bigmatrix [k] [l]) == แหล่งที่มา [x] [y]) {count ++; } else break cout; y ++; } x ++; } // system.out.println ("count =" + นับ); if (count == comparecount) ส่งคืนจริง; }}} return false; } / *** ตัดเมทริกซ์** @param แหล่งที่มา* แหล่งที่มาเมทริกซ์* @param x* x พิกัด* @param y* y พิกัด* @param width* ความกว้างของเมทริกซ์* @param ความสูง* ความสูงของเมทริกซ์* @return {byte [] [] resultBytes = byte ใหม่ [ความสูง] [ความกว้าง]; สำหรับ (int i = y, k = 0; i <ความสูง+y; i ++, k ++) {สำหรับ (int j = x, l = 0; j <width+x; j ++, l ++) {resultbytes [k] [l] = แหล่งที่มา [i] [j]; // system.out.println ("แหล่งที่มา [" + i + "] [" + j + "]" + "=" + // แหล่งที่มา [i] [j] + "," + "resultbytes [" // + k + "] [" + l + "] =" + resultbytes [k] [l]; }} return resultBytes; } / *** แปลงภาพเป็นอาร์เรย์เมทริกซ์** @param filepath* เส้นทางไฟล์* @return ส่งคืนเมทริกซ์* @throws ยกเว้น* ข้อยกเว้นอาจถูกโยนลง* / ไบต์ส่วนตัว [] [] imagetomatrix int w = image.getWidth (null); int h = image.getheight (null); bufferedImage src = new bufferedImage (w, h, bufferedimage.type_int_rgb); src.getGraphics (). drawimage (ภาพ, 0, 0, null); ไบต์ [] [] สี = ไบต์ใหม่ [h] [w]; สำหรับ (int i = 0; i <h; i ++) {สำหรับ (int j = 0; j <w; j ++) {int rgb = src.getRgb (j, i); // การประมวลผลสีเทาของสตริงพิกเซล Sred = Integer.toHexstring (RGB) .substring (2, 4); String sgreen = integer.tohexstring (rgb) .substring (4, 6); String sblank = integer.tohexstring (rgb) .substring (6, 8); Long Ired = math.round ((Integer.parseint (Sred, 16) * 0.3 + 0.5d)); Long Green = Math.round ((Integer.ParseInt (SGREEN, 16) * 0.59 + 0.5D)); Long Iblank = math.round ((Integer.parseint (Sblank, 16) * 0.11 + 0.5d)); Long Al = Ired + Green + Iblank; // ถ้า (al> 127) // system.out.print ("" + ""); // else // system.out.print ("" + "1"); // system.out.print ("" + (tempint> = maxint? 0: 1)); // system.out.println ("tempint =" + tempint); / * แปลงภาพเป็น 0,1 * // // ค่าที่นี่สามารถแก้ไขได้เป็นค่าที่คุณต้องตัดสินในสีในอนาคต [i] [j] = (ไบต์) (อัล> 127? 0: 1); } // system.out.println (); } คืนสี; } / ** * พิมพ์เมทริกซ์ * * @param matrix * / private static สุดท้าย void printmatrix (byte [] [] matrix) {สำหรับ (int i = 0; i <matrix.length; i ++) {สำหรับ (int j = 0; j <matrix [i] อื่น System.out.print ("1"); } system.out.println (); -ข้างต้นเป็นเนื้อหาทั้งหมดของบทความนี้ ฉันหวังว่ามันจะเป็นประโยชน์ต่อการเรียนรู้ของทุกคนและฉันหวังว่าทุกคนจะสนับสนุน wulin.com มากขึ้น