|
...
|
...
|
@@ -6,16 +6,19 @@ import com.zhonglai.luhui.smart.feeder.config.ScheduledConfig; |
|
|
|
import com.zhonglai.luhui.smart.feeder.dto.FishCurveControlCondition;
|
|
|
|
import com.zhonglai.luhui.smart.feeder.service.device.CameraHandle;
|
|
|
|
import com.zhonglai.luhui.smart.feeder.service.device.handle.CameraRtspHandle;
|
|
|
|
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
|
|
|
import org.opencv.core.*;
|
|
|
|
import org.opencv.highgui.HighGui;
|
|
|
|
import org.opencv.imgcodecs.Imgcodecs;
|
|
|
|
import org.opencv.imgproc.Imgproc;
|
|
|
|
import org.opencv.video.BackgroundSubtractorMOG2;
|
|
|
|
import org.opencv.video.Video;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.List;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.concurrent.ScheduledFuture;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
...
|
...
|
@@ -77,6 +80,9 @@ public class FishGroupImageRecognitionService { |
|
|
|
{
|
|
|
|
CameraHandle cameraHandle = InitService.cameraHandle;
|
|
|
|
|
|
|
|
// // 创建一个窗口来显示图像
|
|
|
|
// HighGui.namedWindow("Image", HighGui.WINDOW_AUTOSIZE);
|
|
|
|
|
|
|
|
if(!cameraHandle.isOpen())
|
|
|
|
{
|
|
|
|
if (!cameraHandle.init())
|
|
...
|
...
|
@@ -90,7 +96,10 @@ public class FishGroupImageRecognitionService { |
|
|
|
|
|
|
|
public void stop()
|
|
|
|
{
|
|
|
|
srsService.stop();
|
|
|
|
if(null != srsService)
|
|
|
|
{
|
|
|
|
srsService.stop();
|
|
|
|
}
|
|
|
|
OperatingData.cameraData.setFishGroupImageRecognIsRun(false);
|
|
|
|
backgroundSubtractor.clear();
|
|
|
|
|
|
...
|
...
|
@@ -144,7 +153,22 @@ public class FishGroupImageRecognitionService { |
|
|
|
{
|
|
|
|
if(null != srsService && endTime-DateUtils.getNowTimeMilly()>0)
|
|
|
|
{
|
|
|
|
srsService.push(frame);
|
|
|
|
CameraRtspHandle cameraRtspHandle = (CameraRtspHandle)cameraHandle;
|
|
|
|
Mat mat = cameraRtspHandle.compress(frame);
|
|
|
|
// 将图像转换为二进制数据
|
|
|
|
MatOfByte matOfByte = new MatOfByte();
|
|
|
|
Imgcodecs.imencode(".jpg", mat, matOfByte);
|
|
|
|
byte[] byteArray = matOfByte.toArray();
|
|
|
|
|
|
|
|
logger.info("推送图片大小:"+(byteArray.length/1024)+"kb");
|
|
|
|
String base64String = Base64.getEncoder().encodeToString(byteArray);
|
|
|
|
mqttService.pullimg(base64String.getBytes());
|
|
|
|
|
|
|
|
// // 显示图像
|
|
|
|
// HighGui.imshow("Image", mat);
|
|
|
|
// HighGui.waitKey(1);
|
|
|
|
matOfByte.release();
|
|
|
|
mat.release();
|
|
|
|
}else {
|
|
|
|
if(null != srsService)
|
|
|
|
{
|
|
...
|
...
|
@@ -197,101 +221,114 @@ public class FishGroupImageRecognitionService { |
|
|
|
|
|
|
|
double[] dsTotal = new double[5];
|
|
|
|
|
|
|
|
|
|
|
|
contours.removeIf(matOfPoint -> {
|
|
|
|
Rect rect = Imgproc.boundingRect(matOfPoint);
|
|
|
|
matOfPoint.release();
|
|
|
|
|
|
|
|
double[] ds = count(image,rect);
|
|
|
|
|
|
|
|
dsTotal[0]+=ds[0];
|
|
|
|
dsTotal[1]+=ds[1];
|
|
|
|
dsTotal[2]+=ds[2];
|
|
|
|
dsTotal[4]++;
|
|
|
|
if(rect.width!=image.width() && rect.width>OperatingData.cameraConfig.getCalloutBoxWidthMin())
|
|
|
|
{
|
|
|
|
double[] ds = count(image,rect);
|
|
|
|
|
|
|
|
if(filterate(ds))
|
|
|
|
{
|
|
|
|
dsTotal[0]+=ds[0];
|
|
|
|
dsTotal[1]+=ds[1];
|
|
|
|
dsTotal[2]+=ds[2];
|
|
|
|
dsTotal[3]+=ds[3];
|
|
|
|
dsTotal[4]++;
|
|
|
|
Imgproc.rectangle(image, rect.tl(), rect.br(), new Scalar(0, 255, 0), 2);
|
|
|
|
return false;
|
|
|
|
}else{
|
|
|
|
dsTotal[3]+=0;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
dsTotal[3]+=0;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
if(0!=dsTotal[4])
|
|
|
|
if(0==dsTotal[4])
|
|
|
|
{
|
|
|
|
double brightness = dsTotal[0]/dsTotal[4];
|
|
|
|
double reflection= dsTotal[1]/dsTotal[4];
|
|
|
|
double transparencyMeasure= dsTotal[2]/dsTotal[4];
|
|
|
|
double area = dsTotal[3]/dsTotal[4];
|
|
|
|
|
|
|
|
//计算斜率
|
|
|
|
double slope = area - (null==OperatingData.cameraData.getArea()?area:OperatingData.cameraData.getArea());
|
|
|
|
//当前斜率的差值
|
|
|
|
double slopeDifference = slope-(null==OperatingData.cameraData.getSlope()?slope:OperatingData.cameraData.getSlope());
|
|
|
|
//计算斜率差值的绝对值
|
|
|
|
double absValue = Math.abs(slopeDifference);
|
|
|
|
|
|
|
|
OperatingData.cameraData.setBrightness(brightness);
|
|
|
|
OperatingData.cameraData.setReflection(reflection);
|
|
|
|
OperatingData.cameraData.setTransparencyMeasure(transparencyMeasure);
|
|
|
|
OperatingData.cameraData.setArea(area);
|
|
|
|
OperatingData.cameraData.setSlope(slope);
|
|
|
|
OperatingData.cameraData.setSlopeDifference(slopeDifference);
|
|
|
|
OperatingData.cameraData.setAbsValue(absValue);
|
|
|
|
OperatingData.cameraData.setSize(new Double(dsTotal[4]).intValue());
|
|
|
|
|
|
|
|
List<Double> scaleAreaList = OperatingData.cameraData.getScaleAreaList();
|
|
|
|
//计算尺度之内的面积集合的大小
|
|
|
|
int size = new Double((OperatingData.cameraConfig.getCollectionScale()*60*1000l)/time).intValue();
|
|
|
|
//如何集合满了,就吧第一个挤出去,然后放在集合最后
|
|
|
|
if(scaleAreaList.size()>=size)
|
|
|
|
{
|
|
|
|
scaleAreaList.remove(0);
|
|
|
|
}
|
|
|
|
scaleAreaList.add(dsTotal[4]);
|
|
|
|
|
|
|
|
//计算鱼群规模
|
|
|
|
Double[] fishSchoolSizeConfig = OperatingData.cameraConfig.getFishSchoolSizeConfig();
|
|
|
|
int grade = 0;
|
|
|
|
double fishSchoolSize = area*dsTotal[4];
|
|
|
|
System.out.println("=======鱼群规模:"+fishSchoolSize+"=========");
|
|
|
|
for (int i=0;i<fishSchoolSizeConfig.length;i++)
|
|
|
|
{
|
|
|
|
if(fishSchoolSize-fishSchoolSizeConfig[i]>0)
|
|
|
|
{
|
|
|
|
grade = i+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(OperatingData.cameraData.getFishSchoolSize()!=grade)
|
|
|
|
{
|
|
|
|
OperatingData.cameraData.setFishSchoolSize(grade);
|
|
|
|
if(OperatingData.cameraConfig.getIfSendFishSchoolSize())
|
|
|
|
{
|
|
|
|
int finalGrade = grade;
|
|
|
|
ScheduledConfig.scheduler.schedule(() -> {
|
|
|
|
|
|
|
|
String nowtime = DateUtils.getTime();
|
|
|
|
String[] ss = OperatingData.cameraConfig.getFishSchoolSizeConfigString();
|
|
|
|
String fishSchoolSizeStr = ss[finalGrade];
|
|
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
|
|
stringBuffer.append(nowtime);
|
|
|
|
stringBuffer.append(" ");
|
|
|
|
stringBuffer.append(fishSchoolSizeStr);
|
|
|
|
// stringBuffer.append(",当前档位:");
|
|
|
|
// stringBuffer.append(null==OperatingData.cameraData.getNowGear()?0:OperatingData.cameraData.getNowGear());
|
|
|
|
// stringBuffer.append("档");
|
|
|
|
InitService.dateListenService.reportIntelligentFeeding(stringBuffer.toString());
|
|
|
|
|
|
|
|
},0, TimeUnit.SECONDS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.info("当前画面的亮度:{},当前画面的反光:{},当前画面的透明度:{},当前画面的平均面积:{},鱼群规模:{},鱼群数量:{}",brightness,reflection,transparencyMeasure,area,fishSchoolSize, OperatingData.cameraData.getSize());
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
List<Double> scaleAreaList = OperatingData.cameraData.getScaleAreaList();
|
|
|
|
//计算尺度之内的面积集合的大小
|
|
|
|
int size = new Double((OperatingData.cameraConfig.getCollectionScale()*60*1000l)/time).intValue();
|
|
|
|
//如何集合满了,就吧第一个挤出去,然后放在集合最后
|
|
|
|
if(scaleAreaList.size()>=size)
|
|
|
|
{
|
|
|
|
scaleAreaList.remove(0);
|
|
|
|
}
|
|
|
|
scaleAreaList.add(dsTotal[3]);
|
|
|
|
OperatingData.cameraData.setBrightness(new BigDecimal(dsTotal[0]/dsTotal[4]).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
|
|
|
OperatingData.cameraData.setReflection(new BigDecimal(dsTotal[1]/dsTotal[4]).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
|
|
|
OperatingData.cameraData.setTransparencyMeasure(new BigDecimal(dsTotal[2]/dsTotal[4]).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
|
|
|
OperatingData.cameraData.setArea(new BigDecimal(dsTotal[3]/dsTotal[4]).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
|
|
|
OperatingData.cameraData.setFishSchoolSize(new Double(dsTotal[3]).intValue());
|
|
|
|
OperatingData.cameraData.setSize(new Double(dsTotal[4]).intValue());
|
|
|
|
|
|
|
|
// if(0!=dsTotal[4])
|
|
|
|
// {
|
|
|
|
// double brightness = dsTotal[0]/dsTotal[4];
|
|
|
|
// double reflection= dsTotal[1]/dsTotal[4];
|
|
|
|
// double transparencyMeasure= dsTotal[2]/dsTotal[4];
|
|
|
|
// double area = dsTotal[3]/dsTotal[4];
|
|
|
|
//
|
|
|
|
// //计算斜率
|
|
|
|
// double slope = area - (null==OperatingData.cameraData.getArea()?area:OperatingData.cameraData.getArea());
|
|
|
|
// //当前斜率的差值
|
|
|
|
// double slopeDifference = slope-(null==OperatingData.cameraData.getSlope()?slope:OperatingData.cameraData.getSlope());
|
|
|
|
// //计算斜率差值的绝对值
|
|
|
|
// double absValue = Math.abs(slopeDifference);
|
|
|
|
//
|
|
|
|
// OperatingData.cameraData.setBrightness(brightness);
|
|
|
|
// OperatingData.cameraData.setReflection(reflection);
|
|
|
|
// OperatingData.cameraData.setTransparencyMeasure(transparencyMeasure);
|
|
|
|
// OperatingData.cameraData.setArea(area);
|
|
|
|
// OperatingData.cameraData.setSlope(slope);
|
|
|
|
// OperatingData.cameraData.setSlopeDifference(slopeDifference);
|
|
|
|
// OperatingData.cameraData.setAbsValue(absValue);
|
|
|
|
// OperatingData.cameraData.setSize(new Double(dsTotal[4]).intValue());
|
|
|
|
//
|
|
|
|
// //计算鱼群规模
|
|
|
|
// Double[] fishSchoolSizeConfig = OperatingData.cameraConfig.getFishSchoolSizeConfig();
|
|
|
|
// int grade = 0;
|
|
|
|
// double fishSchoolSize = dsTotal[3];
|
|
|
|
// System.out.println("=======鱼群规模:"+fishSchoolSize+"=========");
|
|
|
|
// for (int i=0;i<fishSchoolSizeConfig.length;i++)
|
|
|
|
// {
|
|
|
|
// if(fishSchoolSize-fishSchoolSizeConfig[i]>0)
|
|
|
|
// {
|
|
|
|
// grade = i+1;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if(OperatingData.cameraData.getFishSchoolSize()!=grade)
|
|
|
|
// {
|
|
|
|
// OperatingData.cameraData.setFishSchoolSize(grade);
|
|
|
|
// if(OperatingData.cameraConfig.getIfSendFishSchoolSize())
|
|
|
|
// {
|
|
|
|
// int finalGrade = grade;
|
|
|
|
// ScheduledConfig.scheduler.schedule(() -> {
|
|
|
|
//
|
|
|
|
// String nowtime = DateUtils.getTime();
|
|
|
|
// String[] ss = OperatingData.cameraConfig.getFishSchoolSizeConfigString();
|
|
|
|
// String fishSchoolSizeStr = ss[finalGrade];
|
|
|
|
// StringBuffer stringBuffer = new StringBuffer();
|
|
|
|
// stringBuffer.append(nowtime);
|
|
|
|
// stringBuffer.append(" ");
|
|
|
|
// stringBuffer.append(fishSchoolSizeStr);
|
|
|
|
//// stringBuffer.append(",当前档位:");
|
|
|
|
//// stringBuffer.append(null==OperatingData.cameraData.getNowGear()?0:OperatingData.cameraData.getNowGear());
|
|
|
|
//// stringBuffer.append("档");
|
|
|
|
// InitService.dateListenService.reportIntelligentFeeding(stringBuffer.toString());
|
|
|
|
//
|
|
|
|
// },0, TimeUnit.SECONDS);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// logger.info("当前画面的亮度:{},当前画面的反光:{},当前画面的透明度:{},当前画面的平均面积:{},鱼群规模:{},鱼群数量:{}",brightness,reflection,transparencyMeasure,area,fishSchoolSize, OperatingData.cameraData.getSize());
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
...
|
...
|
|