Main.java file...:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | import net.sourceforge.tess4j.ITessAPI; import net.sourceforge.tess4j.Tesseract1; import net.sourceforge.tess4j.TesseractException; import org.bytedeco.javacpp.opencv_core.IplImage; import org.bytedeco.javacpp.opencv_core.IplConvKernel; import org.bytedeco.javacv.CanvasFrame; import static org.bytedeco.javacpp.opencv_highgui.*; import static org.bytedeco.javacpp.opencv_imgproc.*; import static org.bytedeco.javacpp.opencv_core.*; public class ResimPlakaBul { public static void main(String[] args) { IplConvKernel morfo = IplConvKernel.create(3, 3,1, 1, CV_SHAPE_RECT,null); IplImage resim =cvLoadImage("d:/masaustu/Plaka/snapshots/tr/a (37).jpg"); // IplImage plaka = cvLoadImage(arg0) CanvasFrame frame = new CanvasFrame("Resim"); CanvasFrame frame1 = new CanvasFrame("Plaka Alanı"); frame.showImage(resim); OpenCvDeneme plakabul = new OpenCvDeneme(); try { // plakabul.plakaBul(plakabul.Cevir(resim)); plakabul.plakaBul(resim); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } IplImage roiCikis =(plakabul.getRoiCikis().clone()); cvSaveImage("plaka.jpg", roiCikis); //SaveImage("plaka.jpg", plakabul.Cevir(roiCikis));; ///cvFlip(roiCikis,roiCikis,90); frame1.showImage(roiCikis); } } |
OpenCvDeneme.java Plaka Bulan dosya...:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | import java.awt.image.BufferedImage; import org.bytedeco.javacpp.opencv_core.IplImage; import static org.bytedeco.javacpp.helper.opencv_core.CV_RGB; import static org.bytedeco.javacpp.opencv_core.*; import static org.bytedeco.javacpp.opencv_imgproc.*; import org.bytedeco.javacpp.opencv_core; import org.bytedeco.javacpp.opencv_highgui; import org.bytedeco.javacpp.opencv_objdetect.CascadeClassifier; import org.bytedeco.javacv.CanvasFrame; import org.bytedeco.javacpp.opencv_core.CvPoint; import org.bytedeco.javacpp.opencv_core.Mat; import org.bytedeco.javacpp.opencv_core.Rect; import org.bytedeco.javacpp.opencv_core.Size; import com.recognition.software.jdeskew.ImageDeskew; public class OpenCvDeneme { static IplImage roiCikis,sizeImage,gray_image,dondu,cevir; //CanvasFrame ilkresim = new CanvasFrame("Resim"); int plakaX,plakaY,plakaW,plakaH; public int getPlakaX() { return plakaX; } public void setPlakaX(int plakaX) { this.plakaX = plakaX; } public int getPlakaY() { return plakaY; } public void setPlakaY(int plakaY) { this.plakaY = plakaY; } public int getPlakaW() { return plakaW; } public void setPlakaW(int plakaW) { this.plakaW = plakaW; } public int getPlakaH() { return plakaH; } public void setPlakaH(int plakaH) { this.plakaH = plakaH; } public static IplImage getDondu() { return dondu; } public static void setDondu(IplImage dondu) { OpenCvDeneme.dondu = dondu; } public static IplImage getCevir() { return cevir; } public static void setCevir(IplImage cevir) { OpenCvDeneme.cevir = cevir; } public static IplImage getRoiCikis() { return roiCikis; } public static void setRoiCikis(IplImage roiCikis) { OpenCvDeneme.roiCikis = roiCikis; } public static IplImage getSizeImage() { return sizeImage; } public static void setSizeImage(IplImage sizeImage) { OpenCvDeneme.sizeImage = sizeImage; } public static IplImage getGray_image() { return gray_image; } public static void setGray_image(IplImage gray_image) { OpenCvDeneme.gray_image = gray_image; } public void plakaBul (IplImage im) throws InterruptedException{ CascadeClassifier plakaBulucu = new CascadeClassifier("xml/eu.xml"); IplConvKernel morfo = IplConvKernel.create(3, 3, 1, 1, CV_SHAPE_RECT,null); // im = org.bytedeco.javacpp.opencv_highgui.cvLoadImage("c:/users/fevzi/desktop/Plaka/snapshots/tr/a (49).jpg"); //CanvasFrame ilkResim = new CanvasFrame("İlk Resm"); IplImage im2 =IplImage.create(im.width(),im.height(),im.depth(),im.nChannels()); cvCopy(im, im2); IplImage sizeImage2 = IplImage.create(1024,768, im2.depth(),im2.nChannels()); cvResize(im2, sizeImage2); sizeImage = IplImage.create(1024,768, im.depth(),im.nChannels()); gray_image = IplImage.create(sizeImage.width(),sizeImage.height(), IPL_DEPTH_8U, 1); //cevir=Cevir(im); cvResize(im, sizeImage); cvCvtColor(sizeImage, gray_image, CV_BGR2GRAY); cvSmooth(gray_image, gray_image, CV_GAUSSIAN, 3,3, 1, 1); cvEqualizeHist(gray_image, gray_image); //cvThreshold(gray_image, gray_image, 125, 255, CV_THRESH_BINARY); //cvSmooth(gray_image, gray_image, CV_GAUSSIAN, 7, 7, 1, 1); //cvDilate(gray_image, gray_image, morfo, 2); //cvErode(gray_image, gray_image, morfo, 1); //cvDilate(gray_image, gray_image, null, 1); //cvErode(gray_image, gray_image, null, 1); //cvAdaptiveThreshold(gray_image, gray_image, 255, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY, 11, 3); //cvThreshold(gray_image, gray_image, 15, 255, CV_THRESH_BINARY); cvMorphologyEx(gray_image, gray_image,null, morfo, CV_MOP_OPEN,1); cvMorphologyEx(gray_image, gray_image,null, morfo, CV_MOP_CLOSE,1); //cvCanny(gray_image, gray_image, 5.1, 1); Mat resimGiris = new Mat(gray_image, true); Rect detectGiris = new Rect(); //plakaBulucu.detectMultiScale(resimGiris, detectGiris,1.1, 1,1, new Size(20, 20), new Size(300, 300)); plakaBulucu.detectMultiScale(resimGiris, detectGiris); /* cvRectangle( sizeImage2, cvPoint(detectGiris.x(), detectGiris.y()), cvPoint(detectGiris.x() + detectGiris.width(), detectGiris.y() + detectGiris.height()), cvScalar(0, 255, 0, 0), 2, 8, 0); */ setPlakaX(detectGiris.asCvRect().x()); setPlakaY(detectGiris.asCvRect().y()); setPlakaH(detectGiris.asCvRect().height()); setPlakaW(detectGiris.asCvRect().width()); opencv_core.cvSetImageROI(sizeImage2, cvRect(detectGiris.asCvRect().x()-10, detectGiris.asCvRect().y(),detectGiris.asCvRect().width()+10, detectGiris.asCvRect().height())); roiCikis = IplImage.create(cvGetSize(sizeImage2), sizeImage2.depth(), sizeImage2.nChannels()); opencv_core.cvCopy(sizeImage2, roiCikis); // cevir=Cevir(roiCikis); opencv_core.cvResetImageROI(sizeImage2); // ilkresim.showImage(sizeImage2); } public static opencv_core.IplImage Cevir(opencv_core.IplImage image) { BufferedImage img = image.getBufferedImage(); ImageDeskew cevirAci = new ImageDeskew(img); double aci = cevirAci.getSkewAngle(); opencv_core.IplImage copy = cvCloneImage(image); opencv_core.IplImage rotatedImage = cvCreateImage(cvGetSize(copy), copy.depth(), copy.nChannels()); //Define Rotational Matrix opencv_core.CvMat mapMatrix = cvCreateMat(2, 3, CV_32FC1); //Define Mid Point opencv_core.CvPoint2D32f centerPoint = new opencv_core.CvPoint2D32f(); centerPoint.x(copy.width() / 2); centerPoint.y(copy.height() / 2); //Get Rotational Matrix cv2DRotationMatrix(centerPoint, aci, 1.0, mapMatrix); //Rotate the Image cvWarpAffine(copy, rotatedImage, mapMatrix, CV_INTER_CUBIC + CV_WARP_FILL_OUTLIERS, cvScalarAll(255)); cvReleaseImage(copy); cvReleaseMat(mapMatrix); return rotatedImage; } } |
Ekran Görüntüsü....
i cant install tess4j on my computer becouse the 32 bit,
YanıtlaSilhttp://codehouses.blogspot.com.tr/2014/03/how-to-use-tess4j-on-windows-8-64-bit.html
Silplease add ue.xml and full src codes zip?
YanıtlaSiloncelikle cok tesekkur ederim. JavaCV hangi versiyonunu kullandiniz? Cunki bazi methotlari gormuyor proje. Mesela, cvSaveImage, frame1.showImage, cvLoadImage gibi methotlarda hata veriyor.
YanıtlaSilYeni versiyonun da ;OpenCVFrameConverter kullanman gerekli.
Siladresi: http://bytedeco.org/news/2015/04/04/javacv-frame-converters/
OpenCVFrameConverter.ToIplImage converterIPL = new OpenCVFrameConverter.ToIplImage();
Java2DFrameConverter convertToBuffer = new Java2DFrameConverter();
OpenCVFrameConverter.ToMat convertToMat = new OpenCVFrameConverter.ToMat();
IplImage grabimage;
FFmpegFrameGrabber grabber ;
grabimage = converterIPL.convertToIplImage(grabber.grabImage());
Merhaba eu.xml dosyasını veya proje dosyasını paylaşma şansınız var mı teşekkürler iyi çalışmalar
YanıtlaSilmerhaba projeyi çalıştıramadım da proje dosyasını atabilme şansınız var mı mailim dogukancagri@hotmail.com
YanıtlaSil