基本的には、キャプチャのテキスト画像に一般的に見られるようなテキストをオーバーレイする可能性がある線を削除したいので、後の画像にはテキストのみが含まれています。どのようにこの問題を解決するための任意の提案をいただければ幸いです。画像から任意の向きの線を取り除く方法
0
A
答えて
0
既存のキャプチャイメージジェネレータを編集しますか(特定のキャプチャの実装に関連している可能性があり、ここで実装コードを公開しないため難しいでしょう)、または新しいキャプチャを生成しますかオーバーレイテキストなしで滑らかできれいに見えます)?
ここでは、自分のJSP Webアプリケーションページのために自分のキャプチャを作成したときのことです。 JSPインポート文を削除し、JAVAインポート文で置き換える必要があります。必要に応じて、コードを自由に編集し、独自のキャプチャを生成することができます(グラフィックを編集する)。お役に立てれば !
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<%@ page import="java.awt.*"%>
<%@ page import="java.awt.image.*"%>
<%@ page import="javax.imageio.*"%>
<%@ page import="java.awt.geom.*"%>
<%
response.setContentType("image/jpg");
try {
Color backgroundColor = Color.green;
Color borderColor = Color.orange;
Color textColor = Color.white;
Color circleColor = Color.green;
Font textFont = new Font("Arial", Font.PLAIN, 24);
int charsToPrint = 6;
int width = request.getParameter("width") != null ? Integer.parseInt(request.getParameter("width")) : 150;
int height = request.getParameter("height") != null ? Integer.parseInt(request.getParameter("height")) : 80;
int circlesToDraw = 6;
float horizMargin = 20.0f;
float imageQuality = 0.95f; // max is 1.0 (this is for jpeg)
double rotationRange = 0.7; // this is radians
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) bufferedImage.getGraphics();
//Draw an oval
g.setColor(Color.DARK_GRAY);
g.fillRect(0, 0, width, height);
// lets make some noisey circles
g.setColor(circleColor);
for (int i = 0; i < circlesToDraw; i++) {
int circleRadius = (int) (Math.random() * height/2.0);
int circleX = (int) (Math.random() * width - circleRadius);
int circleY = (int) (Math.random() * height - circleRadius);
g.drawOval(circleX, circleY, circleRadius * 2, circleRadius * 2);
}
g.setColor(textColor);
g.setFont(textFont);
FontMetrics fontMetrics = g.getFontMetrics();
int maxAdvance = fontMetrics.getMaxAdvance();
int fontHeight = fontMetrics.getHeight();
// i removed 1 and l and i because there are confusing to users...
// Z, z, and N also get confusing when rotated
// 0, O, and o are also confusing...
// lowercase G looks a lot like a 9 so i killed it
// this should ideally be done for every language...
// i like controlling the characters though because it helps prevent confusion
String elegibleChars = "ABCDEFGHJKLMPQRSTUVWXYabcdefhjkmnpqrstuvwxy23456789";
char[] chars = elegibleChars.toCharArray();
float spaceForLetters = -horizMargin * 2 + width;
float spacePerChar = spaceForLetters/(charsToPrint - 1.0f);
AffineTransform transform = g.getTransform();
StringBuffer finalString = new StringBuffer();
for (int i = 0; i < charsToPrint; i++) {
double randomValue = Math.random();
int randomIndex = (int) Math.round(randomValue * (chars.length - 1));
char characterToShow = chars[randomIndex];
finalString.append(characterToShow);
// this is a separate canvas used for the character so that
// we can rotate it independently
int charImageWidth = maxAdvance * 2;
int charImageHeight = fontHeight * 2;
int charWidth = fontMetrics.charWidth(characterToShow);
int charDim = Math.max(maxAdvance, fontHeight);
int halfCharDim = (int) (charDim/2);
BufferedImage charImage = new BufferedImage(charDim, charDim, BufferedImage.TYPE_INT_ARGB);
Graphics2D charGraphics = charImage.createGraphics();
charGraphics.translate(halfCharDim, halfCharDim);
double angle = (Math.random() - 0.5) * rotationRange;
charGraphics.transform(AffineTransform.getRotateInstance(angle));
charGraphics.translate(-halfCharDim,-halfCharDim);
charGraphics.setColor(textColor);
charGraphics.setFont(textFont);
int charX = (int) (0.5 * charDim - 0.5 * charWidth);
charGraphics.drawString("" + characterToShow, charX,(int) ((charDim - fontMetrics.getAscent())/2 + fontMetrics.getAscent()));
float x = horizMargin + spacePerChar * (i) - charDim/2.0f;
int y = (int) ((height - charDim)/2);
g.drawImage(charImage, (int) x, y, charDim, charDim, null, null);
charGraphics.dispose();
}
//Write the image as a jpg
Iterator iter = ImageIO.getImageWritersByFormatName("JPG");
if(iter.hasNext()) {
ImageWriter writer = (ImageWriter)iter.next();
ImageWriteParam iwp = writer.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionQuality(imageQuality);
writer.setOutput(ImageIO.createImageOutputStream(response.getOutputStream()));
IIOImage imageIO = new IIOImage(bufferedImage, null, null);
writer.write(null, imageIO, iwp);
} else {
throw new RuntimeException("no encoder found for jsp");
}
// let's stick the final string in the session (optional, only if you use JSP session object, and want to save it inside the user session)
session.setAttribute("captcha", finalString.toString());
g.dispose();
}
catch (IOException ioe) {
throw new RuntimeException("Unable to build image" , ioe);
}
%>
+0
実際には反対の - 私はOCRを探検:) :) –
関連する問題
- 1. 画像から不要な線を取り除く
- 2. 画像(Imagik/Gd)から任意の形状を切り取る
- 3. Magento画像の背景から黒の画像を取り除く方法
- 4. 元の画像からクロップされた画像を取り除く方法
- 5. 画像処理で画像からの反射を取り除く方法
- 6. 画像からexifを取り除く
- 7. 画像の周りに黒い枠線を取り除く
- 8. 画像任意の画面
- 9. ajaxの画像アップロードの通知を取り除く方法
- 10. サーバから画像処理の負荷を取り除く方法
- 11. CSS3 a:-webkit-any-linkから下線を取り除く方法
- 12. 画像からざらついた細部を取り除く方法
- 13. CSSで線図の軸線を取り除く方法は?
- 14. 回転行列から任意の回転軸を取り除く
- 15. ブロガーの画像リンクを取り除く
- 16. UISegmentedControlの画像から色合いを取り除くiOS
- 17. スキャンした画像から背景のグラデーションを取り除く
- 18. キャンバスに任意の数の画像を読み込む方法
- 19. PILを使用して任意の画像から透明/アルファを削除
- 20. ファイルを書き、線を取り除く方法は?
- 21. 画像ギャラリーで空白を取り除く方法
- 22. 私のガントチャートから今日の垂直線を取り除く方法
- 23. 画像から垂直方向の空白を削除する方法
- 24. URLを使って任意のウェブサイトから画像を取得するには
- 25. cv2.imread:固定場所から任意の画像ファイルを読み取る
- 26. UIImageの画像を取り除く名前付き:FUD
- 27. jQueryカルーセル - 任意の数の画像
- 28. Androidで描かれた線を取り除く方法
- 29. ウェブページ上に任意の画像を描く
- 30. BABYLON線の照明効果を取り除く方法
これは特定の実装に非常に特有です。テキストと行のストローク幅が異なりますか? – rwong