That just means cvHoughCircles() doesn't support the format of your
image. You'll need to convert it to what it supports as documented here:
https://docs.opencv.org/4.1.2/dd/d1a/group__imgproc__feature.html#ga47849c3be0d0406ad3ca45db65a25d2d
That is: 8-bit, single-channel, grayscale input image.
On 4/14/20 10:18 PM, Viktoria Kübler-Tesch wrote:
> Hi ,I'm new to JavaCV and I'm trying to use this piece of software to
> detect circles in a picture.I found a blogpost online from 2013 and I've
> been trying to adjust it (this is the original source:
>
http://opencvlover.blogspot.com/2012/07/hough-circle-in-javacv.html ).
> However the error (shown in the subject) keeps appearing. I'm assuming
> it is because Java, OpenCV, JavaCV,.. are all on my D:\ drive and the
> program is trying to save/acces something on my C drive and there might
> not be access ?! How do I resolve this? (Thanks in advance)
>
> I'm using Eclipse with the newest OpenJava Development Kit.
> This is the full error message:
>
> Exception in thread "main" java.lang.RuntimeException: OpenCV(4.1.2)
> C:\projects\javacpp-presets\opencv\cppbuild\windows-x86_64\opencv-4.1.2\modules\core\src\matrix_c.cpp:185:
> error: (-5:Bad argument) Unknown array type in function 'cv::cvarrToMat'
>
> at org.bytedeco.opencv.global.opencv_imgproc.cvHoughCircles(Native Method)
> at imageProcess.Main.main(Main.java:67)
>
>
>
> This is the Code (without the imports):
>
>
> public class Main {
>
> public static void main(String[] args) {
>
> //reading the image
> Mat trial= imread("HFSBs.png");
> IplImage trial2= new IplImage (trial);
>
> //more problems -> not gonna convert it to gray
> ///converting it to gray
>
> //CvSize size= trial2.asCvMat().cvSize();
> //IplImage gray = cvCreateImage(size, 8, 1);
> //cvCvtColor(trial2, gray, CV_BGR2GRAY);
>
> //auskommentiert weil vielleicht nicht benötigt+ Methode nicht aufrufbar
> //cvSmooth(gray, gray, CV_GAUSSIAN, 3);
>
>
> //storage for the circles?
> CvMemStorage mem = CvMemStorage.create();
>
>
> //Hough transformation to find the circles
> CvSeq circles = cvHoughCircles(
> trial2, //Input image
> mem, //Memory Storage
> CV_HOUGH_GRADIENT, //Detection method
> 1, //Inverse ratio
> 100, //Minimum distance between the centers of the detected circles
> 100, //Higher threshold for canny edge detector
> 100, //Threshold at the center detection stage
> 15, //min radius
> 500 //max radius
> );
>
>
> for(int i = 0; i < circles.total(); i++){
> CvPoint3D32f circle = (CvPoint3D32f) new CvPoint3D32f(cvGetSeqElem(circles, i));
> CvPoint center = cvPointFrom32f(new CvPoint2D32f(circle.x(), circle.y()));
> int radius = Math.round(circle.z());
> cvCircle(trial2, center, radius, CvScalar.GREEN, 6, CV_AA, 0);
> }
>
> //display picture
>
>
> OpenCVFrameConverter.ToIplImage grabberConverter = new OpenCVFrameConverter.ToIplImage();
> Java2DFrameConverter paintConverter = new Java2DFrameConverter();
> Frame frame = grabberConverter.convert(trial2);
> BufferedImage trial3= paintConverter.getBufferedImage(frame,1);
>
> CanvasFrame displayFrame= new CanvasFrame("Result");
> displayFrame.showImage(trial3);
>
> //cvShowImage("Result",trial2);
> KeyEvent key;
> try {
> key = displayFrame.waitKey(0);
> } catch (InterruptedException e) {
> System.out.print(e.getMessage());
> e.printStackTrace();
> }
>
>
> }
> }
>