/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ru.sfedu.opencvweb.webapi;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import org.apache.log4j.Logger;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import ru.sfedu.opencvgraphic.api.MyAPI;
/**
*
* @author maksimustimenko
*/
@Path("/api")
public class FoursLab {
private static Logger logger = Logger.getLogger(FoursLab.class);
public static Boolean inited = false;
MyAPI instance = new MyAPI();
@GET
@Path("/segments")
@Produces("application/json")
public String segments(
@QueryParam("img_name")String imgName,
@QueryParam("min_height")int minHeight,
@QueryParam("min_width")int minWidth,
@QueryParam("max_height")int maxHeight,
@QueryParam("max_width")int maxWidth
) throws Exception{
init();
String path = instance.segment(imgName, minHeight, minWidth, maxHeight, maxWidth);
return "{\"status\": \"images uploaded segments\", \"path\": \"" + path + "\"}";
}
@GET
@Path("/upDownPyramids")
@Produces("application/json")
public String upDownPyramids(
@QueryParam("img_name")String imgName,
@QueryParam("iterations")int iterations
) throws Exception{
init();
String path = instance.upDownPyramids(imgName, iterations);
return "{\"status\": \"images uploaded UPDOWN\", \"path\": \"" + path + "\"}";
}
@GET
@Path("/pyramidDown")
@Produces("application/json")
public String pyramidDown(
@QueryParam("img_name")String imgName,
@QueryParam("iterations")int iterations
) throws Exception{
init();
String path = instance.pyramidDown(imgName, iterations);
return "{\"status\": \"images uploaded DOWN\", \"path\": \"" + path + "\"}";
}
@GET
@Path("/pyramidUp")
@Produces("application/json")
public String pyramidUp(
@QueryParam("img_name")String imgName,
@QueryParam("iterations")int iterations
) throws Exception{
init();
String path = instance.pyramidUp(imgName, iterations);
return "{\"status\": \"images uploaded UP\", \"path\": \"" + path + "\"}";
}
@GET
@Path("/fillFlood")
@Produces("application/json")
public String fillFlood(
@QueryParam("img_name")String imgName,
@QueryParam("color")int color,
@QueryParam("initVal")int initVal
) throws Exception{
init();
String path = instance.fillFlood(imgName, new Point(10, 10), null, new Scalar(initVal,initVal,initVal), new Scalar(initVal,initVal,initVal));
return "{\"status\": \"images uploaded fillFlood\", \"path\": \"" + path + "\"}";
}
@GET
@Path("/filtering")
@Produces("application/json")
public String filtering(
@QueryParam("img_name")String imgName,
@QueryParam("core_size")int coreSize
) throws Exception{
init();
Size core = new Size(coreSize, coreSize);
String path = instance.filtering(imgName, core);
return "{\"status\": \"images uploaded filtering\", \"path\": \"" + path + "\"}";
}
@GET
@Path("/filteringCore")
@Produces("application/json")
public String filteringCore(
@QueryParam("img_name")String imgName
) throws Exception{
init();
String path = instance.filtering_core(imgName);
return "{\"status\": \"images uploaded filtering\", \"path\": \"" + path + "\"}";
}
@GET
@Path("/morfologyTest")
@Produces("application/json")
public String morfologyTest(
@QueryParam("img_name")String imgName
) throws Exception{
init();
String path = instance.morfologyTest(imgName);
return "{\"status\": \"images uploaded morfologyTest\", \"path\": \"" + path + "\"}";
}
@GET
@Path("/changeChanel")
@Produces("application/json")
public String changeChanel(
@QueryParam("img_name")String imgName,
@QueryParam("numChn")int numChn
) throws Exception{
init();
String path = instance.changeChanel(numChn, imgName);
return "{\"status\": \"images uploaded changeChanel\", \"path\": \"" + path + "\"}";
}
public void init() throws Exception{
if (!inited) {
inited = true;
instance.initApi();
}
}
}