In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "OPENCV Chinese display garbled code how to use JAVA processing", the article explained the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "OPENCV Chinese display garbled how to use JAVA processing" it!
1.Imgproc.putText Chinese garbled code
Imgproc.putText (image, new String (("gender:" + gender + "Age:" + age). GetBytes ("UTF-8")), new Point ([I] .x, [I] .y), Imgproc.FONT_HERSHEY_PLAIN, 0.8, sc, 1, Imgproc.LINE_AA, false)
two。 Thinking of problem handling
1.MAT to IMAGE2.IMAGE and then to MAT after adding watermark
3. Code (conversion from the network)
/ * Mat converted to BufferedImage * @ param matrix the Mat * @ param fileExtension format to be converted is ".jpg", ".png", etc * @ return * / public static BufferedImage Mat2BufImg (Mat matrix String fileExtension) {/ / convert the matrix into a matrix of bytes appropriate for / / this file extension MatOfByte mob = new MatOfByte () Imgcodecs.imencode (fileExtension, matrix, mob); / / convert the "matrix of bytes" into a byte array byte [] byteArray = mob.toArray (); BufferedImage bufImage = null; try {InputStream in = new ByteArrayInputStream (byteArray); bufImage = ImageIO.read (in) } catch (Exception e) {e.printStackTrace ();} return bufImage } / * BufferedImage converted to Mat * @ param original the type of BufferedImage * @ param imgType bufferedImage to be converted, such as BufferedImage.TYPE_3BYTE_BGR * @ param matType converted to mat type such as CvType.CV_8UC3 * / public static Mat BufImg2Mat (BufferedImage original, int imgType) Int matType) {if (original = = null) {throw new IllegalArgumentException ("original = = null") } / / System.loadLibrary ("opencv_java412"); / / System.loadLibrary (Core.NATIVE_LIBRARY_NAME); / / System.load ("E:\\ opencv\\ opencv\\ build\\ java\\ x64\\ opencv_java412.dll"); / / System.out.println (Core.NATIVE_LIBRARY_NAME) / / Don't convert if it already has correct type if (original.getType ()! = imgType) {/ / Create a buffered image BufferedImage image = new BufferedImage (original.getWidth (), original.getHeight (), imgType); / / Draw the image onto the new buffer Graphics2D g = image.createGraphics () Try {g.setComposite (AlphaComposite.Src); g.drawImage (original, 0,0, null);} finally {g.dispose () } byte [] pixels = ((DataBufferByte) original.getRaster (). GetDataBuffer ()) .getData (); Mat mat = Mat.eye (original.getHeight (), original.getWidth (), matType); mat.put (0,0, pixels); return mat } / * * @ param cc recognition Class * @ param image Picture * @ param sc Color * @ param flip whether to reverse * @ return * @ throws UnsupportedEncodingException * / private static Map getFace (CascadeClassifier cc,Mat image,Scalar sc,boolean flip) throws UnsupportedEncodingException {Map resultMap=new HashMap () MatOfRect face = new MatOfRect (); if (flip) {Core.flip (image, image, 1);} cc.detectMultiScale (image, face); Rect [] rects = face.toArray () System.out.println ("match to" + rects.length + "personal face"); / / 4 draw a circle for (int I = 0; I < rects.length) for each recognized face Imgproc.rectangle +) {Imgproc.rectangle (image, new Point ([I] .x, [I] .y), new Point (image,rects [I] .x + thanks [I] .width, thanks [I] .y + accouns.height), sc); String age=analyseAge (I]) String gender=analyseGender (image,rects [I]); / / Font font = new Font ("Microsoft Yahi", Font.PLAIN, 12); BufferedImage bufImg = Mat2BufImg (image, ".png"); Graphics2D g = bufImg.createGraphics () G.drawImage (bufImg, 0,0, bufImg.getWidth (), bufImg.getHeight (), null); g.setFont (font); / / set font / / set the coordinates of the watermark g.drawString ("gender:" + gender+ "age:" + age, g.dispose [I] .y); g.dispose () Image=ImageUtil.BufImg2Mat (bufImg, BufferedImage.TYPE_3BYTE_BGR, CvType.CV_8UC3) / / CvType.CV_8UC3 / * * Imgproc.putText (image, new String (("gender:" + gender + "age:" + * age) .getBytes ("UTF-8")), new Point ([I] .x, [I] .y), * Imgproc.FONT_HERSHEY_PLAIN 0.8, sc, 1, Imgproc.LINE_AA, false) * /} if (flip) {Core.flip (image, image, 1);} boolean check=rects.length
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.