Java Code Examples for org.opencv.core.CvType#CV_32SC1

The following examples show how to use org.opencv.core.CvType#CV_32SC1 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TrainFaces.java    From classchecks with Apache License 2.0 6 votes vote down vote up
public static boolean updateTrainModel() {
	List<Mat> matLists = new ArrayList<Mat>(); // 待训练的人脸图片集合
	List<Integer> lableLists = new ArrayList<Integer>(); // 人脸图片对应的标签
	String CSVFilePath = "E:\\classchecks\\Test\\2017417\\train\\at.txt";
	CSVFileUtils.CSVRead(CSVFilePath, matLists, lableLists);

	// opencv 在训练人脸模型时需要确保人脸与标签一一对应
	if(matLists.size() == lableLists.size()) {
		Mat labels = new Mat(lableLists.size(), 1, CvType.CV_32SC1, new Scalar(0));
		for(int i = 0; i < lableLists.size(); i ++) {
			labels.put(i, 0, new int[]{lableLists.get(i)});
		}
		
		BasicFaceRecognizer faceRecognizer = load("E:\\classchecks\\test.xml");
		faceRecognizer.update(matLists, labels);
	}
	
	return false;
}
 
Example 2
Source File: Converters.java    From Android-Car-duino with GNU General Public License v2.0 5 votes vote down vote up
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
    if (is == null)
        throw new java.lang.IllegalArgumentException("is == null");
    int count = m.rows();
    if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32SC1 != m.type() ||  m.cols()!=1\n" + m);

    is.clear();
    int[] buff = new int[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        is.add(buff[i]);
    }
}
 
Example 3
Source File: Converters.java    From PixaToon with GNU General Public License v3.0 5 votes vote down vote up
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
    if (is == null)
        throw new java.lang.IllegalArgumentException("is == null");
    int count = m.rows();
    if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32SC1 != m.type() ||  m.cols()!=1\n" + m);

    is.clear();
    int[] buff = new int[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        is.add(buff[i]);
    }
}
 
Example 4
Source File: Converters.java    From android-object-distance with Apache License 2.0 5 votes vote down vote up
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
    if (is == null)
        throw new IllegalArgumentException("is == null");
    int count = m.rows();
    if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
        throw new IllegalArgumentException(
                "CvType.CV_32SC1 != m.type() ||  m.cols()!=1\n" + m);

    is.clear();
    int[] buff = new int[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        is.add(buff[i]);
    }
}
 
Example 5
Source File: Converters.java    From MOAAP with MIT License 5 votes vote down vote up
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
    if (is == null)
        throw new java.lang.IllegalArgumentException("is == null");
    int count = m.rows();
    if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32SC1 != m.type() ||  m.cols()!=1\n" + m);

    is.clear();
    int[] buff = new int[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        is.add(buff[i]);
    }
}
 
Example 6
Source File: Converters.java    From SmartPaperScan with Apache License 2.0 5 votes vote down vote up
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
    if (is == null)
        throw new java.lang.IllegalArgumentException("is == null");
    int count = m.rows();
    if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32SC1 != m.type() ||  m.cols()!=1\n" + m);

    is.clear();
    int[] buff = new int[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        is.add(buff[i]);
    }
}
 
Example 7
Source File: Converters.java    From real_time_circle_detection_android with MIT License 5 votes vote down vote up
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
    if (is == null)
        throw new java.lang.IllegalArgumentException("is == null");
    int count = m.rows();
    if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32SC1 != m.type() ||  m.cols()!=1\n" + m);

    is.clear();
    int[] buff = new int[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        is.add(buff[i]);
    }
}
 
Example 8
Source File: Converters.java    From FtcSamples with MIT License 5 votes vote down vote up
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
    if (is == null)
        throw new java.lang.IllegalArgumentException("is == null");
    int count = m.rows();
    if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32SC1 != m.type() ||  m.cols()!=1\n" + m);

    is.clear();
    int[] buff = new int[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        is.add(buff[i]);
    }
}
 
Example 9
Source File: Converters.java    From FaceT with Mozilla Public License 2.0 5 votes vote down vote up
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
    if (is == null)
        throw new java.lang.IllegalArgumentException("is == null");
    int count = m.rows();
    if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32SC1 != m.type() ||  m.cols()!=1\n" + m);

    is.clear();
    int[] buff = new int[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        is.add(buff[i]);
    }
}
 
Example 10
Source File: Converters.java    From OpenCV-AndroidSamples with MIT License 5 votes vote down vote up
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
    if (is == null)
        throw new java.lang.IllegalArgumentException("is == null");
    int count = m.rows();
    if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32SC1 != m.type() ||  m.cols()!=1\n" + m);

    is.clear();
    int[] buff = new int[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        is.add(buff[i]);
    }
}
 
Example 11
Source File: Converters.java    From Chinese-number-gestures-recognition with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
    if (is == null)
        throw new java.lang.IllegalArgumentException("is == null");
    int count = m.rows();
    if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32SC1 != m.type() ||  m.cols()!=1\n" + m);

    is.clear();
    int[] buff = new int[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        is.add(buff[i]);
    }
}
 
Example 12
Source File: UtilTest.java    From OpenTLDAndroid with Apache License 2.0 5 votes vote down vote up
public void testGetVar(){
	final Mat img = new Mat(5, 5, CvType.CV_32SC1);
	img.put(0, 0, IISUM);
	
	final Mat img2 = new Mat(5, 5, CvType.CV_64F);
	img2.put(0, 0, IISQSUM);
	
	final BoundingBox test_box = new BoundingBox(1, 1, 3, 3, 1, 0);
	
	assertEquals("Wrong Var calculation", -417.55555, Util.getVar(test_box, img, img2), 0.00001);
}
 
Example 13
Source File: Converters.java    From sudokufx with Apache License 2.0 5 votes vote down vote up
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
    if (is == null)
        throw new IllegalArgumentException("is == null");
    int count = m.rows();
    if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
        throw new IllegalArgumentException(
                "CvType.CV_32SC1 != m.type() ||  m.cols()!=1\n" + m);

    is.clear();
    int[] buff = new int[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        is.add(buff[i]);
    }
}
 
Example 14
Source File: Util.java    From OpenTLDAndroid with Apache License 2.0 5 votes vote down vote up
static int[] getIntArray(final Mat mat){
	if(CvType.CV_32SC1 != mat.type()) throw new IllegalArgumentException("Expected type is CV_32SC1, we found: " + CvType.typeToString(mat.type()));
	
	final int size = (int) (mat.total() * mat.channels());
	if(_intBuff.length != size){
		_intBuff = new int[size];
	}
	mat.get(0, 0, _intBuff); // 0 for row and col means the WHOLE Matrix
	return _intBuff;
}
 
Example 15
Source File: Converters.java    From ml-authentication with Apache License 2.0 5 votes vote down vote up
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
    if (is == null)
        throw new java.lang.IllegalArgumentException("is == null");
    int count = m.rows();
    if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32SC1 != m.type() ||  m.cols()!=1\n" + m);

    is.clear();
    int[] buff = new int[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        is.add(buff[i]);
    }
}
 
Example 16
Source File: Converters.java    From FTCVision with MIT License 5 votes vote down vote up
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
    if (is == null)
        throw new java.lang.IllegalArgumentException("is == null");
    int count = m.rows();
    if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32SC1 != m.type() ||  m.cols()!=1\n" + m);

    is.clear();
    int[] buff = new int[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        is.add(buff[i]);
    }
}
 
Example 17
Source File: Converters.java    From OpenCV-Android-Object-Detection with MIT License 5 votes vote down vote up
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
    if (is == null)
        throw new java.lang.IllegalArgumentException("is == null");
    int count = m.rows();
    if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32SC1 != m.type() ||  m.cols()!=1\n" + m);

    is.clear();
    int[] buff = new int[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        is.add(buff[i]);
    }
}
 
Example 18
Source File: Converters.java    From SoftwarePilot with MIT License 5 votes vote down vote up
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
    if (is == null)
        throw new java.lang.IllegalArgumentException("is == null");
    int count = m.rows();
    if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32SC1 != m.type() ||  m.cols()!=1\n" + m);

    is.clear();
    int[] buff = new int[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        is.add(buff[i]);
    }
}
 
Example 19
Source File: Util.java    From OpenTLDAndroid with Apache License 2.0 4 votes vote down vote up
static int getInt(final int row, final int col, final Mat mat){
	if(CvType.CV_32SC1 != mat.type()) throw new IllegalArgumentException("Expected type is CV_32SC1, we found: " + CvType.typeToString(mat.type()));
	
	mat.get(row, col, _intBuff1);
	return _intBuff1[0];
}
 
Example 20
Source File: ClockinAsStudentServiceImpl.java    From classchecks with Apache License 2.0 4 votes vote down vote up
@Override
public BasicEntityVo<?> clockin(String jwAccount, String loginAccount, Double lng, Double lat,
		CommonsMultipartFile file) {
	
	LOG.info("学生端考勤Service");
	LOG.info("ContentType:" + file.getContentType() 
		+ " Filename:" + file.getOriginalFilename() + " Size:" + file.getSize());
	LOG.info("学生上传经纬度:lng=" + lng + " lat:" + lat);
	Integer teacherUId = clockinAsStudentMapper.getTeacherIDByStudentClock(jwAccount, 500);
	
	LOG.info("教师UID:" + teacherUId);
	SchoolCourseClockModel sccm = basicService.getSchoolCourseClockModelNow();
	PointVo gpsPoint = clockinAsStudentMapper.getGPSByTeacherID(teacherUId, sccm);
	LOG.info("教师最新考勤记录的GPS坐标:" + gpsPoint);
	
	double stuDistanceTea = PositionUtil.distance(gpsPoint.getLng(), gpsPoint.getLat(), lng, lat);
	
	LOG.info("学生与教师的距离:" + stuDistanceTea);
	
	if(stuDistanceTea > 550) {
		return new BasicEntityVo<>(StudentClockInBusinessCode.GPS_DISTANCE_GT_50[0], StudentClockInBusinessCode.GPS_DISTANCE_GT_50[1]);
	}
	
	Date date = new Date();
	// "yyyy-MM-dd"字符串
	String dtSimpleDate = DateUtil.dtSimpleFormat(date);
	// "yyyyMMddHHmmss"日期字符串
	String longTime = DateUtil.longDate(date);
	// 保存文件路径的每个文件夹名称数组,教师上传的图片以每天的日期作为文件夹
	String [] pathKey = {ImgStoragePath.STUDENT_CLOCK_IN_IMG_PATH, loginAccount, dtSimpleDate};
	// 保存图片的文件夹路径
	String dirSavePath = FileUtils.buildFilePath(pathKey);
	
	boolean isSaved = fileSave(file, dirSavePath, longTime);
	if(isSaved == false) { // 上传的图片保存失败
		return new BasicEntityVo<>(StudentClockInBusinessCode.BUSSINESS_IMAGE_SAVE_FAILED[0], StudentClockInBusinessCode.BUSSINESS_IMAGE_SAVE_FAILED[1]);
	}
	
	String absolutePath = FileUtils.buildFilePath(dirSavePath, longTime+".jpg");
	Mat imgSrc = Imgcodecs.imread(absolutePath, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE); // 加载上传的图片
	
	Mat procMat = PreProcessFace.smallProcessedFace(imgSrc);
	
	if(null == procMat) {
		return new BasicEntityVo<>(StudentClockInBusinessCode.BUSSINESS_NO_DETECT_FACE[0], StudentClockInBusinessCode.BUSSINESS_NO_DETECT_FACE[1]);
	}
	
	String collecteFaceRoute = FileUtils.buildFilePath(ImgStoragePath.PROC_FACE_IMG_SAVE_PATH, loginAccount);
	
	List<Mat> collectedMats = new ArrayList<Mat>();
	List<Integer> faceLabels = new ArrayList<Integer>();
	CSVFileUtils.loadImage(collecteFaceRoute, collectedMats, faceLabels);
	
	// 将人脸标签放入一个Mat对象,OpenCV提供的人脸识别算法中接收一个存有人脸标签的Mat
	Mat labelsMat = new Mat(faceLabels.size(), 1, CvType.CV_32SC1, new Scalar(0));
	for(int i = 0; i < faceLabels.size(); i ++) {
		labelsMat.put(i, 0, new int[]{faceLabels.get(i)});
	}
	
	// 训练人脸模型,这里使用的是特征脸算法
	BasicFaceRecognizer faceModel = Recognition.learnCollectedFaces(collectedMats, labelsMat);
	
	Mat reconstructedFace = Recognition.reconstructFace(faceModel, procMat);
	double similarity = Recognition.getSimilarity(reconstructedFace, procMat);
	LOG.info("similarity = " + similarity);
	LOG.info("predict_label: "+faceModel.predict_label(procMat));
	
	if(similarity > 0.13) {
		return new BasicEntityVo<>(StudentClockInBusinessCode.FACE_NON_EXISTENT[0], 
				StudentClockInBusinessCode.FACE_NON_EXISTENT[1]);
	}
	
	// 学生自己考勤成功后更新考勤记录
	clockinAsStudentMapper.updateStudentClockinRecord(jwAccount);
	
	StudentClockinVo vo = new StudentClockinVo();
	
	vo.setStuName(clockinAsStudentMapper.findStudentName(jwAccount));
	vo.setCurTime(DateUtil.hmsFormat(new Date()));
	// TODO 更新考勤记录
	return new BasicEntityVo<>(StudentClockInBusinessCode.BUSINESS_SUCCESS[0], 
			StudentClockInBusinessCode.BUSINESS_SUCCESS[1], vo);
}