简体   繁体   English

Java-OpenCV错误:OpenCV错误:断言失败(dims <= 2 && step [0]> 0)

[英]Java- OpenCV Error: OpenCV Error: Assertion failed (dims <= 2 && step[0] > 0)

I have this opencv code. 我有这个opencv代码。 Which makes a convolution to an image that I found in a page. 这使得我在页面中找到的图像卷积。 I wanted to try it, but it gives the following error and I do not know much about openCV. 我想尝试一下,但它给出了以下错误,我对openCV了解不多。 I need help. 我需要帮助。

Error: OpenCV Error: Assertion failed (dims <= 2 && step[0] > 0) in cv::Mat::locateROI, file C:\\build\\master_winpack-bindings-win64-vc14-static\\opencv\\modules\\core\\src\\matrix.cpp, line 949 错误:OpenCV错误:断言失败(dims <= 2 && step [0]> 0)在cv :: Mat :: locateROI中,文件C:\\ build \\ master_winpack-bindings-win64-vc14-static \\ opencv \\ modules \\ core \\ src \\ matrix.cpp,第949行

 public class main { public static void main (String [ ] args) { System.out.println ("hola"); try { int kernelSize = 3; System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); Mat source = Imgcodecs.imread("logo.png", Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE); Mat destination = new Mat(source.rows(),source.cols(),source.type()); Mat kernel = new Mat(kernelSize,kernelSize, CvType.CV_32F){ { put(0,0,0); put(0,1,0); put(0,2,0); put(1,0,0); put(1,1,1); put(1,2,0); put(2,0,0); put(2,1,0); put(2,2,0); } }; Imgproc.filter2D(source, destination, -1, kernel); Imgcodecs.imwrite("original.jpg", destination); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } } } 

Had the same error and followed the very valuable hint of @Miki. 有同样的错误,并遵循@Miki非常有价值的提示。 In my case the image wasn't loaded properly because of unsuitable bit-depth. 在我的情况下,由于不适合的位深度,图像未正确加载。 32 instead of 8 bit for a greyscale image. 对于灰度图像,32而不是8位。

看起来您的源和目标是单通道,而您的内核是3通道。

I had the same exact error before so when I wrote the whole path of the picture, My code worked very well , so be careful with the extension of the image and make sure that your picture exists 我之前有同样的错误,当我写完图片的整个路径时,我的代码工作得非常好,所以要小心图片的扩展并确保你的图片存在

Here is what I did : 这是我做的:

pic = cv2.imread('C:\Users\WSI\Desktop\python_scripts\hakuoki.jpg',cv2.IMREAD_COLOR)

I had the same error, I wrote png instead of jpg in the file name. 我有同样的错误,我在文件名中写了png而不是jpg。 Make sure you load image with the proper extension/name 确保使用正确的扩展名/名称加载图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java OpenCV错误内存不足和断言失败 - java opencv error insufficient memory and assertion failed OpenCV错误:断言失败(src.dims == 2 &amp;&amp; info.height ==(uint32_t) - OpenCV Error: Assertion failed (src.dims == 2 && info.height == (uint32_t) OpenCV Android CamShift断言失败错误 - OpenCV Android CamShift Assertion failed error OpenCV错误:在Java和OpenCV 3.0中断言失败(!empty()),这是什么意思? - OpenCV Error: Assertion failed (!empty()) in java and opencv 3.0 and what does it mean? OpenCV错误:未知函数,文件(Java + opencv 2.4.6)中的断言失败(ptnum&gt; 3) - OpenCV Error: Assertion failed (ptnum > 3) in unknown function, file (Java + opencv 2.4.6) detectMultiScale中的OpenCV断言错误 - OpenCV Assertion Error in detectMultiScale 断言失败与Android中的OpenCV进行模板匹配时出错 - Assertion failed Error during template matching with OpenCV in Android OpenCV错误:断言失败(ksize.width&gt; ...表示GaussianBlur - OpenCV Error: Assertion failed (ksize.width > … for GaussianBlur OpenCV错误:在OpenCV android sdk中使用分水岭时断言失败(scn == 3 || scn == 4) - OpenCV Error: Assertion failed (scn == 3 || scn == 4) while using Watershed in OpenCV android sdk Opencv Android上的矩阵乘法给出断言错误 - Matrix multiplication on Opencv Android gives assertion error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM