Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Como resolve esse erro t org.opencv.imgproc.Imgproc.blur_2(Native Method)

Olá a todos, estou criando um sistema pra reconhecimento de objetos, mais precisamente de placas de carro, é para um sistema de controle pra praia de minha cidade. Estou usando o Java e a ultima versão do OpenCv 4.3.0, consigo abrir a câmera sem erros.O problema esta no codigo para reconhecimento de placas, está dando erros, mas que é sobre a versão ou algo do tipo. Vou deixar o codigo das classes, e dos erro, espero que alguém possa me ajudar. CLASSE DE ENTRADA

public class entrada {
public static void main(String[] args) {
try {
// carregando a biblioteca
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.out.println("começando");
int[] mm = { 10,100 };
int[] nn = { 10,100,300 };
int[] aa = { 1 };
int[] bb = { 5};
int[] cc = { 5,10,15 };
int[] dd = { 3 };
int[] ee = {200};
for (int m = 0; m < mm.length; m++) {
for (int n = 0; n < nn.length; n++) {
for (int a = 0; a < aa.length; a++) {
for (int b = 0; b < bb.length; b++) {
for (int c = 0; c < cc.length; c++) {

for (int d = 0; d < dd.length; d++) {
for(int e = 0; e < ee.length;e++){
// carregando a imagem original, ja em escala de cinza
    Mat imageGray = Imgcodecs.imread("C:\\Users\\PC\\Desktop\\placa.jpg\"");
BufferedImage temp = reconhecimento.reconhecedorPlaca(imageGray, mm[m], nn[n],
aa[a], bb[b], cc[c], dd[d],ee[e]);
File outputfile = new File("final" + aa[a]
+ "x" + bb[b] + "x" + cc[c] + "x" + dd[d] + "x" +ee[e]
+"x"
+ ".jpg");
ImageIO.write(temp, "jpg", outputfile);
}}}}}}}
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
}
}

CLASSE 2 public class reconhecimento {

public static int ver =0;

public static BufferedImage reconhecedorPlaca(Mat matrix,int m,int n,int a,int b,int c,int d,

int e ) {

int cols = matrix.cols(); int rows = matrix.rows();

int elemSize = (int)matrix.elemSize();

byte[] data = new byte[cols * rows * elemSize];

int type;

Mat imagemResultanteCanny = new Mat(matrix.rows(),matrix.cols(),CvType.CV_8UC1);

Imgproc.blur(matrix, imagemResultanteCanny,new Size(3,3)); Imgproc.Canny(imagemResultanteCanny, imagemResultanteCanny, m, n, 3, true); Imgcodecs.imwrite("canny"+m+"x"+n+"x3ver"+ver+".jpg", imagemResultanteCanny); ver++;

Mat lines = new Mat(); Imgproc.HoughLinesP(imagemResultanteCanny, lines, 2, Math.PI/180, b, c, d); System.out.println(lines.size());

for (int x = 0; x < lines.cols(); x++) { double[] vec = lines.get(0, x);

org.opencv.core.Point start = new org.opencv.core.Point(); start.x = (int) vec[0]; start.y = (int) vec[1];

org.opencv.core.Point end = new org.opencv.core.Point(); end.x = (int) vec[2]; end.y = (int) vec[3];

Imgproc.line(matrix, start, end, new Scalar(255,255,255), 2); }

Mat imagemResultanteCorner = new Mat();

 Imgproc.cornerHarris(imagemResultanteCanny, imagemResultanteCorner, 2, 3, 0.04, 1);

 Mat n_norm = new Mat();
normalize(imagemResultanteCorner, n_norm,0,255,Core.compareTo(Core),CvType.CV_32FC1);
Mat s_norm = new Mat();
//Imgproc.conveScaleAbs(n_norm, s_norm);
Imgcodecs.imwrite("corner"+m+"x"+n+"x"+a+"x"+b+"x"+c+"x"+d+"x"+e+"ver"+ver+".jpg",
s_norm);
 for(int y = 0; y < imagemResultanteCorner.height(); y++){
 for(int x = 0; x < imagemResultanteCorner.width(); x++){
 if(s_norm.get(y,x)[0] > e ){
 Imgproc.circle(matrix, new org.opencv.core.Point(x,y),10, new Scalar(255), 2,8,0);
 }
 }
 }

 switch (matrix.channels()) {
 case 1:
 type = BufferedImage.TYPE_BYTE_GRAY;
 break;
 case 3:
 type = BufferedImage.TYPE_3BYTE_BGR;
 byte bI;
 for(int i=0; i<data.length; i=i+3) {

 bI = data[i];
 data[i] = data[i+2];
 data[i+2] = bI;
 }
 break;
 default:
 return null;
 }
matrix.get(0, 0, data);
 BufferedImage image2 = new BufferedImage(cols, rows, type);
 image2.getRaster().setDataElements(0, 0, cols, rows, data);
 return image2;


 }
}
}

ERRO

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.3.0) C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\imgproc\src\box_filter.dispatch.cpp:446: error: (-215:Assertion failed) !_src.empty() in function 'cv::boxFilter'
]
    at org.opencv.imgproc.Imgproc.blur_2(Native Method)
    at org.opencv.imgproc.Imgproc.blur(Imgproc.java:4288)

Como resolve esse erro t org.opencv.imgproc.Imgproc.blur_2(Native Method)

Olá Hello everyone, I am creating a todos, estou criando um sistema pra reconhecimento de objetos, mais precisamente de placas de carro, é para um sistema de controle pra praia de minha cidade. Estou usando o system for object recognition, more precisely for license plates, it is for a control system for the beach in my city. I'm using Java e a ultima versão do and the latest version of OpenCv 4.3.0, consigo abrir a câmera sem erros.O problema esta no codigo para reconhecimento de placas, está dando erros, mas que é sobre a versão ou algo do tipo. Vou deixar o codigo das I can open the camera without errors. The problem is in the code for plate recognition, it's giving errors, but it's about the version or something. I will leave the code of the classes, e dos erro, espero que alguém possa me ajudar. CLASSE DE ENTRADAand the errors, I hope someone can help me. ENTRY CLASS

public class entrada {
public static void main(String[] args) {
try {
// carregando a biblioteca
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.out.println("começando");
int[] mm = { 10,100 };
int[] nn = { 10,100,300 };
int[] aa = { 1 };
int[] bb = { 5};
int[] cc = { 5,10,15 };
int[] dd = { 3 };
int[] ee = {200};
for (int m = 0; m < mm.length; m++) {
for (int n = 0; n < nn.length; n++) {
for (int a = 0; a < aa.length; a++) {
for (int b = 0; b < bb.length; b++) {
for (int c = 0; c < cc.length; c++) {

for (int d = 0; d < dd.length; d++) {
for(int e = 0; e < ee.length;e++){
// carregando a imagem original, ja em escala de cinza
    Mat imageGray = Imgcodecs.imread("C:\\Users\\PC\\Desktop\\placa.jpg\"");
BufferedImage temp = reconhecimento.reconhecedorPlaca(imageGray, mm[m], nn[n],
aa[a], bb[b], cc[c], dd[d],ee[e]);
File outputfile = new File("final" + aa[a]
+ "x" + bb[b] + "x" + cc[c] + "x" + dd[d] + "x" +ee[e]
+"x"
+ ".jpg");
ImageIO.write(temp, "jpg", outputfile);
}}}}}}}
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
}
}

CLASSE 2 public class reconhecimento {

public static int ver =0;

public static BufferedImage reconhecedorPlaca(Mat matrix,int m,int n,int a,int b,int c,int d,

int e ) {

int cols = matrix.cols(); int rows = matrix.rows();

int elemSize = (int)matrix.elemSize();

byte[] data = new byte[cols * rows * elemSize];

int type;

Mat imagemResultanteCanny = new Mat(matrix.rows(),matrix.cols(),CvType.CV_8UC1);

Imgproc.blur(matrix, imagemResultanteCanny,new Size(3,3)); Imgproc.Canny(imagemResultanteCanny, imagemResultanteCanny, m, n, 3, true); Imgcodecs.imwrite("canny"+m+"x"+n+"x3ver"+ver+".jpg", imagemResultanteCanny); ver++;

Mat lines = new Mat(); Imgproc.HoughLinesP(imagemResultanteCanny, lines, 2, Math.PI/180, b, c, d); System.out.println(lines.size());

for (int x = 0; x < lines.cols(); x++) { double[] vec = lines.get(0, x);

org.opencv.core.Point start = new org.opencv.core.Point(); start.x = (int) vec[0]; start.y = (int) vec[1];

org.opencv.core.Point end = new org.opencv.core.Point(); end.x = (int) vec[2]; end.y = (int) vec[3];

Imgproc.line(matrix, start, end, new Scalar(255,255,255), 2); }

Mat imagemResultanteCorner = new Mat();

 Imgproc.cornerHarris(imagemResultanteCanny, imagemResultanteCorner, 2, 3, 0.04, 1);

 Mat n_norm = new Mat();
normalize(imagemResultanteCorner, n_norm,0,255,Core.compareTo(Core),CvType.CV_32FC1);
Mat s_norm = new Mat();
//Imgproc.conveScaleAbs(n_norm, s_norm);
Imgcodecs.imwrite("corner"+m+"x"+n+"x"+a+"x"+b+"x"+c+"x"+d+"x"+e+"ver"+ver+".jpg",
s_norm);
 for(int y = 0; y < imagemResultanteCorner.height(); y++){
 for(int x = 0; x < imagemResultanteCorner.width(); x++){
 if(s_norm.get(y,x)[0] > e ){
 Imgproc.circle(matrix, new org.opencv.core.Point(x,y),10, new Scalar(255), 2,8,0);
 }
 }
 }

 switch (matrix.channels()) {
 case 1:
 type = BufferedImage.TYPE_BYTE_GRAY;
 break;
 case 3:
 type = BufferedImage.TYPE_3BYTE_BGR;
 byte bI;
 for(int i=0; i<data.length; i=i+3) {

 bI = data[i];
 data[i] = data[i+2];
 data[i+2] = bI;
 }
 break;
 default:
 return null;
 }
matrix.get(0, 0, data);
 BufferedImage image2 = new BufferedImage(cols, rows, type);
 image2.getRaster().setDataElements(0, 0, cols, rows, data);
 return image2;


 }
}
}

ERRO

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.3.0) C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\imgproc\src\box_filter.dispatch.cpp:446: error: (-215:Assertion failed) !_src.empty() in function 'cv::boxFilter'
]
    at org.opencv.imgproc.Imgproc.blur_2(Native Method)
    at org.opencv.imgproc.Imgproc.blur(Imgproc.java:4288)

Como resolve esse erro t org.opencv.imgproc.Imgproc.blur_2(Native Method)

Hello everyone, I am creating a system for object recognition, more precisely for license plates, it is for a control system for the beach in my city. I'm using Java and the latest version of OpenCv 4.3.0, I can open the camera without errors. The problem is in the code for plate recognition, it's giving errors, but it's about the version or something. I will leave the code of the classes, and the errors, I hope someone can help me. ENTRY CLASS

public class entrada {
public static void main(String[] args) {
try {
// carregando a biblioteca
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.out.println("começando");
int[] mm = { 10,100 };
int[] nn = { 10,100,300 };
int[] aa = { 1 };
int[] bb = { 5};
int[] cc = { 5,10,15 };
int[] dd = { 3 };
int[] ee = {200};
for (int m = 0; m < mm.length; m++) {
for (int n = 0; n < nn.length; n++) {
for (int a = 0; a < aa.length; a++) {
for (int b = 0; b < bb.length; b++) {
for (int c = 0; c < cc.length; c++) {

for (int d = 0; d < dd.length; d++) {
for(int e = 0; e < ee.length;e++){
// carregando a imagem original, ja em escala de cinza
    Mat imageGray = Imgcodecs.imread("C:\\Users\\PC\\Desktop\\placa.jpg\"");
BufferedImage temp = reconhecimento.reconhecedorPlaca(imageGray, mm[m], nn[n],
aa[a], bb[b], cc[c], dd[d],ee[e]);
File outputfile = new File("final" + aa[a]
+ "x" + bb[b] + "x" + cc[c] + "x" + dd[d] + "x" +ee[e]
+"x"
+ ".jpg");
ImageIO.write(temp, "jpg", outputfile);
}}}}}}}
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
}
}

CLASSE 2 public class reconhecimento {

public static int ver =0;

public static BufferedImage reconhecedorPlaca(Mat matrix,int m,int n,int a,int b,int c,int d,

int e ) {

int cols = matrix.cols(); int rows = matrix.rows();

int elemSize = (int)matrix.elemSize();

byte[] data = new byte[cols * rows * elemSize];

int type;

Mat imagemResultanteCanny = new Mat(matrix.rows(),matrix.cols(),CvType.CV_8UC1);

Imgproc.blur(matrix, imagemResultanteCanny,new Size(3,3)); Imgproc.Canny(imagemResultanteCanny, imagemResultanteCanny, m, n, 3, true); Imgcodecs.imwrite("canny"+m+"x"+n+"x3ver"+ver+".jpg", imagemResultanteCanny); ver++;

Mat lines = new Mat(); Imgproc.HoughLinesP(imagemResultanteCanny, lines, 2, Math.PI/180, b, c, d); System.out.println(lines.size());

for (int x = 0; x < lines.cols(); x++) { double[] vec = lines.get(0, x);

org.opencv.core.Point start = new org.opencv.core.Point(); start.x = (int) vec[0]; start.y = (int) vec[1];

org.opencv.core.Point end = new org.opencv.core.Point(); end.x = (int) vec[2]; end.y = (int) vec[3];

Imgproc.line(matrix, start, end, new Scalar(255,255,255), 2); }

Mat imagemResultanteCorner = new Mat();

 Imgproc.cornerHarris(imagemResultanteCanny, imagemResultanteCorner, 2, 3, 0.04, 1);

 Mat n_norm = new Mat();
normalize(imagemResultanteCorner, n_norm,0,255,Core.compareTo(Core),CvType.CV_32FC1);
Mat s_norm = new Mat();
//Imgproc.conveScaleAbs(n_norm, s_norm);
Imgcodecs.imwrite("corner"+m+"x"+n+"x"+a+"x"+b+"x"+c+"x"+d+"x"+e+"ver"+ver+".jpg",
s_norm);
 for(int y = 0; y < imagemResultanteCorner.height(); y++){
 for(int x = 0; x < imagemResultanteCorner.width(); x++){
 if(s_norm.get(y,x)[0] > e ){
 Imgproc.circle(matrix, new org.opencv.core.Point(x,y),10, new Scalar(255), 2,8,0);
 }
 }
 }

 switch (matrix.channels()) {
 case 1:
 type = BufferedImage.TYPE_BYTE_GRAY;
 break;
 case 3:
 type = BufferedImage.TYPE_3BYTE_BGR;
 byte bI;
 for(int i=0; i<data.length; i=i+3) {

 bI = data[i];
 data[i] = data[i+2];
 data[i+2] = bI;
 }
 break;
 default:
 return null;
 }
matrix.get(0, 0, data);
 BufferedImage image2 = new BufferedImage(cols, rows, type);
 image2.getRaster().setDataElements(0, 0, cols, rows, data);
 return image2;


 }
}
}

ERRO

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.3.0) C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\imgproc\src\box_filter.dispatch.cpp:446: error: (-215:Assertion failed) !_src.empty() in function 'cv::boxFilter'
]
    at org.opencv.imgproc.Imgproc.blur_2(Native Method)
    at org.opencv.imgproc.Imgproc.blur(Imgproc.java:4288)
click to hide/show revision 4
None

updated 2020-07-11 07:09:51 -0600

berak gravatar image

Como resolve esse erro t org.opencv.imgproc.Imgproc.blur_2(Native torg.opencv.imgproc.Imgproc.blur_2(Native Method)

Hello everyone, I am creating a system for object recognition, more precisely for license plates, it is for a control system for the beach in my city. I'm using Java and the latest version of OpenCv 4.3.0, I can open the camera without errors. The problem is in the code for plate recognition, it's giving errors, but it's about the version or something. I will leave the code of the classes, and the errors, I hope someone can help me. ENTRY CLASS

public class entrada {
public static void main(String[] args) {
try {
// carregando a biblioteca
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.out.println("começando");
int[] mm = { 10,100 };
int[] nn = { 10,100,300 };
int[] aa = { 1 };
int[] bb = { 5};
int[] cc = { 5,10,15 };
int[] dd = { 3 };
int[] ee = {200};
for (int m = 0; m < mm.length; m++) {
for (int n = 0; n < nn.length; n++) {
for (int a = 0; a < aa.length; a++) {
for (int b = 0; b < bb.length; b++) {
for (int c = 0; c < cc.length; c++) {

for (int d = 0; d < dd.length; d++) {
for(int e = 0; e < ee.length;e++){
// carregando a imagem original, ja em escala de cinza
    Mat imageGray = Imgcodecs.imread("C:\\Users\\PC\\Desktop\\placa.jpg\"");
BufferedImage temp = reconhecimento.reconhecedorPlaca(imageGray, mm[m], nn[n],
aa[a], bb[b], cc[c], dd[d],ee[e]);
File outputfile = new File("final" + aa[a]
+ "x" + bb[b] + "x" + cc[c] + "x" + dd[d] + "x" +ee[e]
+"x"
+ ".jpg");
ImageIO.write(temp, "jpg", outputfile);
}}}}}}}
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
}
}

CLASSE 2 public class reconhecimento {

public static int ver =0;

public static BufferedImage reconhecedorPlaca(Mat matrix,int m,int n,int a,int b,int c,int d,

int e ) {

int cols = matrix.cols(); int rows = matrix.rows();

int elemSize = (int)matrix.elemSize();

byte[] data = new byte[cols * rows * elemSize];

int type;

Mat imagemResultanteCanny = new Mat(matrix.rows(),matrix.cols(),CvType.CV_8UC1);

Imgproc.blur(matrix, imagemResultanteCanny,new Size(3,3)); Imgproc.Canny(imagemResultanteCanny, imagemResultanteCanny, m, n, 3, true); Imgcodecs.imwrite("canny"+m+"x"+n+"x3ver"+ver+".jpg", imagemResultanteCanny); ver++;

Mat lines = new Mat(); Imgproc.HoughLinesP(imagemResultanteCanny, lines, 2, Math.PI/180, b, c, d); System.out.println(lines.size());

for (int x = 0; x < lines.cols(); x++) { double[] vec = lines.get(0, x);

org.opencv.core.Point start = new org.opencv.core.Point(); start.x = (int) vec[0]; start.y = (int) vec[1];

org.opencv.core.Point end = new org.opencv.core.Point(); end.x = (int) vec[2]; end.y = (int) vec[3];

Imgproc.line(matrix, start, end, new Scalar(255,255,255), 2); }

Mat imagemResultanteCorner = new Mat();

 Imgproc.cornerHarris(imagemResultanteCanny, imagemResultanteCorner, 2, 3, 0.04, 1);

 Mat n_norm = new Mat();
normalize(imagemResultanteCorner, n_norm,0,255,Core.compareTo(Core),CvType.CV_32FC1);
Mat s_norm = new Mat();
//Imgproc.conveScaleAbs(n_norm, s_norm);
Imgcodecs.imwrite("corner"+m+"x"+n+"x"+a+"x"+b+"x"+c+"x"+d+"x"+e+"ver"+ver+".jpg",
s_norm);
 for(int y = 0; y < imagemResultanteCorner.height(); y++){
 for(int x = 0; x < imagemResultanteCorner.width(); x++){
 if(s_norm.get(y,x)[0] > e ){
 Imgproc.circle(matrix, new org.opencv.core.Point(x,y),10, new Scalar(255), 2,8,0);
 }
 }
 }

 switch (matrix.channels()) {
 case 1:
 type = BufferedImage.TYPE_BYTE_GRAY;
 break;
 case 3:
 type = BufferedImage.TYPE_3BYTE_BGR;
 byte bI;
 for(int i=0; i<data.length; i=i+3) {

 bI = data[i];
 data[i] = data[i+2];
 data[i+2] = bI;
 }
 break;
 default:
 return null;
 }
matrix.get(0, 0, data);
 BufferedImage image2 = new BufferedImage(cols, rows, type);
 image2.getRaster().setDataElements(0, 0, cols, rows, data);
 return image2;


 }
}
}

ERRO

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.3.0) C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\imgproc\src\box_filter.dispatch.cpp:446: error: (-215:Assertion failed) !_src.empty() in function 'cv::boxFilter'
]
    at org.opencv.imgproc.Imgproc.blur_2(Native Method)
    at org.opencv.imgproc.Imgproc.blur(Imgproc.java:4288)

Como how to resolve esse erro torg.opencv.imgproc.Imgproc.blur_2(Native org.opencv.imgproc.Imgproc.blur_2(Native Method)

Hello everyone, I am creating a system for object recognition, more precisely for license plates, it is for a control system for the beach in my city. I'm using Java and the latest version of OpenCv 4.3.0, I can open the camera without errors. The problem is in the code for plate recognition, it's giving errors, but it's about the version or something. I will leave the code of the classes, and the errors, I hope someone can help me. ENTRY CLASS

CLASS
public class entrada {
public static void main(String[] args) {
try {
// carregando a biblioteca
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.out.println("começando");
int[] mm = { 10,100 };
int[] nn = { 10,100,300 };
int[] aa = { 1 };
int[] bb = { 5};
int[] cc = { 5,10,15 };
int[] dd = { 3 };
int[] ee = {200};
for (int m = 0; m < mm.length; m++) {
for (int n = 0; n < nn.length; n++) {
for (int a = 0; a < aa.length; a++) {
for (int b = 0; b < bb.length; b++) {
for (int c = 0; c < cc.length; c++) {

for (int d = 0; d < dd.length; d++) {
for(int e = 0; e < ee.length;e++){
// carregando a imagem original, ja em escala de cinza
    Mat imageGray = Imgcodecs.imread("C:\\Users\\PC\\Desktop\\placa.jpg\"");
BufferedImage temp = reconhecimento.reconhecedorPlaca(imageGray, mm[m], nn[n],
aa[a], bb[b], cc[c], dd[d],ee[e]);
File outputfile = new File("final" + aa[a]
+ "x" + bb[b] + "x" + cc[c] + "x" + dd[d] + "x" +ee[e]
+"x"
+ ".jpg");
ImageIO.write(temp, "jpg", outputfile);
}}}}}}}
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
}
}

CLASSE 2 public class reconhecimento {

public static int ver =0;

public static BufferedImage reconhecedorPlaca(Mat matrix,int m,int n,int a,int b,int c,int d,

int e ) {

int cols = matrix.cols(); int rows = matrix.rows();

int elemSize = (int)matrix.elemSize();

byte[] data = new byte[cols * rows * elemSize];

int type;

Mat imagemResultanteCanny = new Mat(matrix.rows(),matrix.cols(),CvType.CV_8UC1);

Imgproc.blur(matrix, imagemResultanteCanny,new Size(3,3)); Imgproc.Canny(imagemResultanteCanny, imagemResultanteCanny, m, n, 3, true); Imgcodecs.imwrite("canny"+m+"x"+n+"x3ver"+ver+".jpg", imagemResultanteCanny); ver++;

Mat lines = new Mat(); Imgproc.HoughLinesP(imagemResultanteCanny, lines, 2, Math.PI/180, b, c, d); System.out.println(lines.size());

for (int x = 0; x < lines.cols(); x++) { double[] vec = lines.get(0, x);

org.opencv.core.Point start = new org.opencv.core.Point(); start.x = (int) vec[0]; start.y = (int) vec[1];

org.opencv.core.Point end = new org.opencv.core.Point(); end.x = (int) vec[2]; end.y = (int) vec[3];

Imgproc.line(matrix, start, end, new Scalar(255,255,255), 2); }

Mat imagemResultanteCorner = new Mat();

 Imgproc.cornerHarris(imagemResultanteCanny, imagemResultanteCorner, 2, 3, 0.04, 1);

 Mat n_norm = new Mat();
normalize(imagemResultanteCorner, n_norm,0,255,Core.compareTo(Core),CvType.CV_32FC1);
Mat s_norm = new Mat();
//Imgproc.conveScaleAbs(n_norm, s_norm);
Imgcodecs.imwrite("corner"+m+"x"+n+"x"+a+"x"+b+"x"+c+"x"+d+"x"+e+"ver"+ver+".jpg",
s_norm);
 for(int y = 0; y < imagemResultanteCorner.height(); y++){
 for(int x = 0; x < imagemResultanteCorner.width(); x++){
 if(s_norm.get(y,x)[0] > e ){
 Imgproc.circle(matrix, new org.opencv.core.Point(x,y),10, new Scalar(255), 2,8,0);
 }
 }
 }

 switch (matrix.channels()) {
 case 1:
 type = BufferedImage.TYPE_BYTE_GRAY;
 break;
 case 3:
 type = BufferedImage.TYPE_3BYTE_BGR;
 byte bI;
 for(int i=0; i<data.length; i=i+3) {

 bI = data[i];
 data[i] = data[i+2];
 data[i+2] = bI;
 }
 break;
 default:
 return null;
 }
matrix.get(0, 0, data);
 BufferedImage image2 = new BufferedImage(cols, rows, type);
 image2.getRaster().setDataElements(0, 0, cols, rows, data);
 return image2;


 }
}
}

ERRO

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.3.0) C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\imgproc\src\box_filter.dispatch.cpp:446: error: (-215:Assertion failed) !_src.empty() in function 'cv::boxFilter'
]
    at org.opencv.imgproc.Imgproc.blur_2(Native Method)
    at org.opencv.imgproc.Imgproc.blur(Imgproc.java:4288)

I think this error is here Imgproc.blur(matrix, imagemResultanteCanny,new Size(3,3)); Imgproc.Canny(imagemResultanteCanny, imagemResultanteCanny, m, n, 3, true); Imgcodecs.imwrite("canny"+m+"x"+n+"x3ver"+ver+".jpg", imagemResultanteCanny);

how to resolve org.opencv.imgproc.Imgproc.blur_2(Native Method)

Hello everyone, I am creating a system for object recognition, more precisely for license plates, it is for a control system for the beach in my city. I'm using Java and the latest version of OpenCv 4.3.0, I can open the camera without errors. The problem is in the code for plate recognition, it's giving errors, but it's about the version or something. I will leave the code of the classes, and the errors, I hope someone can help me. ENTRY CLASS
CLASS

public class entrada {
    public static void main(String[] args) {
        try {
            // carregando a biblioteca
            System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
            System.out.println("começando");
            int[] mm = { 10,100 };
            int[] nn = { 10,100,300 };
            int[] aa = { 1 };
            int[] bb = { 5};
            int[] cc = { 5,10,15 };
            int[] dd = { 3 };
            int[] ee = {200};
            for (int m = 0; m < mm.length; m++) {
             for (int n = 0; n < nn.length; n++) {
              for (int a = 0; a < aa.length; a++) {
               for (int b = 0; b < bb.length; b++) {
                for (int c = 0; c < cc.length; c++) {
                 for (int d = 0; d < dd.length; d++) {
                  for(int e = 0; e < ee.length;e++){
                     // carregando a imagem original, ja em escala de cinza
                     Mat imageGray = Imgcodecs.imread("C:\\Users\\PC\\Desktop\\placa.jpg\"");
                     BufferedImage temp = reconhecimento.reconhecedorPlaca(imageGray, 
                            mm[m], nn[n], aa[a], bb[b], cc[c], dd[d],ee[e]);

                      File outputfile = new File("final" + aa[a]
                       + "x" + bb[b] + "x" + cc[c] + "x" + dd[d] + "x" +ee[e]
                        +"x"+ ".jpg");

                       ImageIO.write(temp, "jpg", outputfile);
            }}}}}}}
        } catch (IOException e) {
        System.out.println("Error: " + e.getMessage());
    }
}

CLASSE 2

public class reconhecimento {


 public static int ver =0;
 public static BufferedImage reconhecedorPlaca(Mat matrix,int m,int n,int a,int b,int c,int d,int e ) {

     int cols = matrix.cols();
     int rows = matrix.rows();

     int elemSize = (int)matrix.elemSize();

     byte[] data = new byte[cols * rows * elemSize];

     int type;

     Mat imagemResultanteCanny = new  Mat(matrix.rows(),matrix.cols(),CvType.CV_8UC1);

     Imgproc.blur(matrix, imagemResultanteCanny,new Size(3,3));
     Imgproc.Canny(imagemResultanteCanny, imagemResultanteCanny, m, n, 3, true);
     Imgcodecs.imwrite("canny"+m+"x"+n+"x3ver"+ver+".jpg", imagemResultanteCanny);
     ver++;

     Mat lines = new Mat();
     Imgproc.HoughLinesP(imagemResultanteCanny, lines, 2, Math.PI/180, b, c, d);
     System.out.println(lines.size());

     for (int x = 0; x < lines.cols(); x++)
     {
         double[] vec = lines.get(0, x);

         org.opencv.core.Point start = new org.opencv.core.Point();
         start.x = (int) vec[0];
         start.y = (int) vec[1];

         org.opencv.core.Point end = new org.opencv.core.Point();
         end.x = (int) vec[2];
         end.y = (int) vec[3];

         Imgproc.line(matrix, start, end, new Scalar(255,255,255), 2); 
     }



    Mat imagemResultanteCorner = new Mat();

     Imgproc.cornerHarris(imagemResultanteCanny, imagemResultanteCorner, 2, 3, 0.04, 1);

     Mat n_norm = new Mat();
     normalize(imagemResultanteCorner, n_norm,0,255,Core.compareTo(Core),CvType.CV_32FC1);
    Mat s_norm = new Mat();
     //Imgproc.conveScaleAbs(n_norm, s_norm);
     Imgcodecs.imwrite("corner"+m+"x"+n+"x"+a+"x"+b+"x"+c+"x"+d+"x"+e+"ver"+ver+".jpg",s_norm);
     for(int y = 0; y < imagemResultanteCorner.height(); y++){
         for(int x = 0; x < imagemResultanteCorner.width(); x++){
             if(s_norm.get(y,x)[0] > e ){
                 Imgproc.circle(matrix, new org.opencv.core.Point(x,y),10, new Scalar(255), 2,8,0);
             }
         }
      }

      switch (matrix.channels()) {
         case 1:
             type = BufferedImage.TYPE_BYTE_GRAY;
             break;
         case 3:
             type = BufferedImage.TYPE_3BYTE_BGR;
            byte bI;
            for(int i=0; i<data.length; i=i+3) {
                 bI = data[i];
                 data[i] = data[i+2];
                 data[i+2] = bI;
             }
             break;
         default:
            return null;
        }

        matrix.get(0, 0, data);
        BufferedImage image2 = new BufferedImage(cols, rows, type);
        image2.getRaster().setDataElements(0, 0, cols, rows, data);
        return image2;


         }
    }

}

ERRO

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.3.0) C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\imgproc\src\box_filter.dispatch.cpp:446: error: (-215:Assertion failed) !_src.empty() in function 'cv::boxFilter'
]
    at org.opencv.imgproc.Imgproc.blur_2(Native Method)
    at org.opencv.imgproc.Imgproc.blur(Imgproc.java:4288)

I think this error is here Imgproc.blur(matrix, imagemResultanteCanny,new Size(3,3)); Imgproc.Canny(imagemResultanteCanny, imagemResultanteCanny, m, n, 3, true); Imgcodecs.imwrite("canny"+m+"x"+n+"x3ver"+ver+".jpg", imagemResultanteCanny);

click to hide/show revision 7
None

updated 2020-07-11 07:23:44 -0600

berak gravatar image

how to resolve org.opencv.imgproc.Imgproc.blur_2(Native Method)

Hello everyone, I am creating a system for object recognition, more precisely for license plates, it is for a control system for the beach in my city. I'm using Java and the latest version of OpenCv 4.3.0, I can open the camera without errors. The problem is in the code for plate recognition, it's giving errors, but it's about the version or something. I will leave the code of the classes, and the errors, I hope someone can help me. ENTRY CLASS

public class entrada {
    public static void main(String[] args) {
        try {
            // carregando a biblioteca
            System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
            System.out.println("começando");
            int[] mm = { 10,100 };
            int[] nn = { 10,100,300 };
            int[] aa = { 1 };
            int[] bb = { 5};
            int[] cc = { 5,10,15 };
            int[] dd = { 3 };
            int[] ee = {200};
            for (int m = 0; m < mm.length; m++) {
             for (int n = 0; n < nn.length; n++) {
              for (int a = 0; a < aa.length; a++) {
               for (int b = 0; b < bb.length; b++) {
                for (int c = 0; c < cc.length; c++) {
                 for (int d = 0; d < dd.length; d++) {
                  for(int e = 0; e < ee.length;e++){
                     // carregando a imagem original, ja em escala de cinza
                     Mat imageGray = Imgcodecs.imread("C:\\Users\\PC\\Desktop\\placa.jpg\"");
                     BufferedImage temp = reconhecimento.reconhecedorPlaca(imageGray, 
                            mm[m], nn[n], aa[a], bb[b], cc[c], dd[d],ee[e]);

                      File outputfile = new File("final" + aa[a]
                       + "x" + bb[b] + "x" + cc[c] + "x" + dd[d] + "x" +ee[e]
                        +"x"+ ".jpg");

                       ImageIO.write(temp, "jpg", outputfile);
            }}}}}}}
        } catch (IOException e) {
        System.out.println("Error: " + e.getMessage());
    }
}

CLASSE 2

public class reconhecimento {


 public static int ver =0;
 public static BufferedImage reconhecedorPlaca(Mat matrix,int m,int n,int a,int b,int c,int d,int e ) {

     int cols = matrix.cols();
     int rows = matrix.rows();

     int elemSize = (int)matrix.elemSize();

     byte[] data = new byte[cols * rows * elemSize];

     int type;

     Mat imagemResultanteCanny = new  Mat(matrix.rows(),matrix.cols(),CvType.CV_8UC1);

     Imgproc.blur(matrix, imagemResultanteCanny,new Size(3,3));
     Imgproc.Canny(imagemResultanteCanny, imagemResultanteCanny, m, n, 3, true);
     Imgcodecs.imwrite("canny"+m+"x"+n+"x3ver"+ver+".jpg", imagemResultanteCanny);
     ver++;

     Mat lines = new Mat();
     Imgproc.HoughLinesP(imagemResultanteCanny, lines, 2, Math.PI/180, b, c, d);
     System.out.println(lines.size());

     for (int x = 0; x < lines.cols(); x++)
     {
         double[] vec = lines.get(0, x);

         org.opencv.core.Point start = new org.opencv.core.Point();
         start.x = (int) vec[0];
         start.y = (int) vec[1];

         org.opencv.core.Point end = new org.opencv.core.Point();
         end.x = (int) vec[2];
         end.y = (int) vec[3];

         Imgproc.line(matrix, start, end, new Scalar(255,255,255), 2); 
     }



    Mat imagemResultanteCorner = new Mat();

     Imgproc.cornerHarris(imagemResultanteCanny, imagemResultanteCorner, 2, 3, 0.04, 1);

     Mat n_norm = new Mat();
     normalize(imagemResultanteCorner, n_norm,0,255,Core.compareTo(Core),CvType.CV_32FC1);
    Mat s_norm = new Mat();
     //Imgproc.conveScaleAbs(n_norm, s_norm);
     Imgcodecs.imwrite("corner"+m+"x"+n+"x"+a+"x"+b+"x"+c+"x"+d+"x"+e+"ver"+ver+".jpg",s_norm);
     for(int y = 0; y < imagemResultanteCorner.height(); y++){
         for(int x = 0; x < imagemResultanteCorner.width(); x++){
             if(s_norm.get(y,x)[0] > e ){
                 Imgproc.circle(matrix, new org.opencv.core.Point(x,y),10, new Scalar(255), 2,8,0);
             }
         }
      }

      switch (matrix.channels()) {
         case 1:
             type = BufferedImage.TYPE_BYTE_GRAY;
             break;
         case 3:
             type = BufferedImage.TYPE_3BYTE_BGR;
            byte bI;
            for(int i=0; i<data.length; i=i+3) {
                 bI = data[i];
                 data[i] = data[i+2];
                 data[i+2] = bI;
             }
             break;
         default:
            return null;
        }

        matrix.get(0, 0, data);
        BufferedImage image2 = new BufferedImage(cols, rows, type);
        image2.getRaster().setDataElements(0, 0, cols, rows, data);
        return image2;


         }
    }

}

ERRO

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.3.0) C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\imgproc\src\box_filter.dispatch.cpp:446: error: (-215:Assertion failed) !_src.empty() in function 'cv::boxFilter'
]
    at org.opencv.imgproc.Imgproc.blur_2(Native Method)
    at org.opencv.imgproc.Imgproc.blur(Imgproc.java:4288)