Solved: The type list is not generic; it cannot be parameterized with arguments <MatOfPoint> [closed]

asked 2018-03-30 10:33:57 -0600

Marko5280 gravatar image

updated 2018-03-30 14:11:23 -0600

I am following samples that use the line …

List<MatOfPoint> contours = new ArrayList<MatOfPoint>();

Example …

List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat notused;
Imgproc.findContours(dilateImg,contours,notused,Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
for(MatOfPoint cont : contours)

The samples claim to be correct but, they in fact do not compile. What am I missing?

Actral code not running ....

vid.read(mat);
if (!mat.empty()){
Mat mono = new Mat();
Imgproc.cvtColor(mat, mat, Imgproc.COLOR_BGR2GRAY);
Mat blur = new Mat();
Imgproc.GaussianBlur(mono, blur, new Size(9, 9), 2, 2);
Mat thresh = new Mat();
Imgproc.threshold(blur, thresh, 0, 255, Imgproc.THRESH_BINARY_INV|Imgproc.THRESH_OTSU);
Mat erodeImg = new Mat();
Mat erode = new Mat();
Imgproc.erode(thresh, erodeImg, erode);
Mat dilateImg = new Mat();
Mat dilate = new Mat();
Imgproc.dilate(erodeImg, dilateImg, dilate);
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();  // This line creates an error!
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by berak
close date 2018-03-31 02:22:00.843001

Comments

opencv version ?

Mat notused = new Mat();

apart from that it compiles successful, here.

berak gravatar imageberak ( 2018-03-30 10:41:38 -0600 )edit

Mat notused = new Mat(); // Is in the sample script for Lego line follower

Eclipse IDE for Java Developers Version: Oxygen.3 Release (4.7.3)

OpenCV 3.4.1

Actual code not running is ...

vid.read(mat);
if (!mat.empty()){
  Mat mono = new Mat();
  Imgproc.cvtColor(mat, mat, Imgproc.COLOR_BGR2GRAY);
  Mat blur = new Mat();
  Imgproc.GaussianBlur(mono, blur, new Size(9, 9), 2, 2);
  Mat thresh = new Mat();
  Imgproc.threshold(blur, thresh,0,255,Imgproc.THRESH_BINARY_INV|Imgproc.THRESH_OTSU);
  Mat erodeImg = new Mat();
  Mat erode = new Mat();
  Imgproc.erode(thresh, erodeImg, erode);
  Mat dilateImg = new Mat();
  Mat dilate = new Mat();
  Imgproc.dilate(erodeImg, dilateImg, dilate);
  List<MatOfPoint> contours = new ArrayLi
Marko5280 gravatar imageMarko5280 ( 2018-03-30 10:58:58 -0600 )edit

^^^ tip for the future: rather edit you question, than putting code into comments (not enough space there, usually)

berak gravatar imageberak ( 2018-03-30 11:53:11 -0600 )edit
Marko5280 gravatar imageMarko5280 ( 2018-03-30 14:29:26 -0600 )edit

ok, so java.util.List instead of the (implicit) java.awt.List.

berak gravatar imageberak ( 2018-03-31 02:22:55 -0600 )edit

This thread was closed prematurely. The answer is farther down the chain of events.

Marko5280 gravatar imageMarko5280 ( 2018-04-13 06:44:23 -0600 )edit