Shift contoure in java

asked 2015-01-17 17:04:58 -0500

mpele gravatar image

I would like to shift contures to the left 10 pixels in Java, but I am not able to find out how to do it.

   List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
   Imgproc.findContours(mat, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); 
   Mat border = new Mat(mat.rows(), mat.cols(), CvType.CV_8UC1); 
   for (MatOfPoint contour : contours) { // iterate over every contour in the list
       Imgproc.drawContours(border, translate(contours), contours.indexOf(contour), new Scalar(255));
   }

I have found some implementation of function translate(contours) but I am not able to rewrite it Java. For example, how to reimplement:

template<class T>
std::vector<cv::Point> translate_contour(std::vector<T> in , int offset_x, int offset_y){
std::vector<cv::Point> ret_contour;
cv::Point2f offset(offset_x,offset_y);
for(int i = 0; i<in.size(); i++){
    int x = (int)(in[i].x+offset_x+0.5);
    int y = (int)(in[i].y+offset_y+0.5);
    ret_contour.push_back(T(x,y));
}
return ret_contour;
}
edit retag flag offensive close merge delete