|
...
|
...
|
@@ -5,16 +5,11 @@ import com.zhonglai.luhui.smart.feeder.dto.ConfigurationParameter; |
|
|
|
import com.zhonglai.luhui.smart.feeder.dto.VeiwDto;
|
|
|
|
import com.zhonglai.luhui.smart.feeder.opencv.OpenCVUtil;
|
|
|
|
import com.zhonglai.luhui.smart.feeder.service.impl.HtmllVeiwServiceImpl;
|
|
|
|
import org.bytedeco.javacv.Frame;
|
|
|
|
import org.bytedeco.javacv.Java2DFrameUtils;
|
|
|
|
import org.bytedeco.javacv.OpenCVFrameConverter;
|
|
|
|
import org.bytedeco.opencv.opencv_core.IplImage;
|
|
|
|
import org.opencv.core.Mat;
|
|
|
|
import org.opencv.core.MatOfPoint;
|
|
|
|
import org.opencv.core.Scalar;
|
|
|
|
import org.opencv.core.Size;
|
|
|
|
import org.opencv.imgproc.Imgproc;
|
|
|
|
import org.opencv.videoio.VideoCapture;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
...
|
...
|
@@ -34,7 +29,7 @@ public class FishGroupImageRecognitionService { |
|
|
|
private static final Logger logger = LoggerFactory.getLogger(FishGroupImageRecognitionService.class);
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private CameraService cameraService;
|
|
|
|
private FFmCameraService fFmCameraService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private ScheduledExecutorService scheduledExecutorService;
|
|
...
|
...
|
@@ -69,19 +64,18 @@ public class FishGroupImageRecognitionService { |
|
|
|
// 创建FrameConverter对象
|
|
|
|
public void start()
|
|
|
|
{
|
|
|
|
if(cameraService.getVideoIsOpen()) //摄像头打开才能识别
|
|
|
|
if(fFmCameraService.getVideoIsOpen()) //摄像头打开才能识别
|
|
|
|
{
|
|
|
|
isRun = true;
|
|
|
|
configurationParameterService.setConfig(ConfigurationParameter.FishGroupImageRecognition,true);
|
|
|
|
VideoCapture videoCapture = cameraService.getVideoCapture();
|
|
|
|
brightnessIdentifyFishRegion(videoCapture);
|
|
|
|
brightnessIdentifyFishRegion();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void stop()
|
|
|
|
{
|
|
|
|
configurationParameterService.setConfig(ConfigurationParameter.FishGroupImageRecognition,false);
|
|
|
|
cameraService.close();
|
|
|
|
fFmCameraService.close();
|
|
|
|
isRun = false;
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -124,15 +118,17 @@ public class FishGroupImageRecognitionService { |
|
|
|
/**
|
|
|
|
* 亮度查找水面,透明度过滤鱼群
|
|
|
|
*/
|
|
|
|
private void brightnessIdentifyFishRegion(VideoCapture videoCapture )
|
|
|
|
private void brightnessIdentifyFishRegion()
|
|
|
|
{
|
|
|
|
logger.info("启动鱼群识别");
|
|
|
|
// 读取第一帧并获取视频大小
|
|
|
|
Mat previousFrame = new Mat();
|
|
|
|
if (!videoCapture.read(previousFrame)) {
|
|
|
|
org.opencv.core.Mat previousFrame = fFmCameraService.getMat();
|
|
|
|
|
|
|
|
if (null == previousFrame) {
|
|
|
|
System.out.println("无法读取视频帧");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.info("鱼群识别时检测摄像头");
|
|
|
|
// 获取水域轮廓
|
|
|
|
if(null != largestContour)
|
|
...
|
...
|
@@ -150,17 +146,16 @@ public class FishGroupImageRecognitionService { |
|
|
|
scheduledExecutorService.scheduleWithFixedDelay(() -> {
|
|
|
|
try {
|
|
|
|
Boolean fishGroupImageRecognition = ((Boolean)configurationParameterService.getConfig(ConfigurationParameter.FishGroupImageRecognition));
|
|
|
|
Mat frame = new Mat();
|
|
|
|
Boolean isread = videoCapture.read(frame);
|
|
|
|
Mat frame = fFmCameraService.getMat();
|
|
|
|
Boolean isread = false;
|
|
|
|
if(null != frame)
|
|
|
|
{
|
|
|
|
isread = true;
|
|
|
|
}
|
|
|
|
logger.info("逐帧处理视频,开始处理的判断参数:鱼群图像识别是否开启 {}、摄像头是否可读取 {}",fishGroupImageRecognition,isread);
|
|
|
|
if(!isread )
|
|
|
|
{
|
|
|
|
logger.info("摄像头不可读取");
|
|
|
|
if(cameraService.getVideoIsOpen())
|
|
|
|
{
|
|
|
|
logger.info("重新初始化");
|
|
|
|
cameraService.clean();
|
|
|
|
}
|
|
|
|
frame.release();
|
|
|
|
return;
|
|
|
|
}
|
...
|
...
|
|