本文整理汇总了Java中org.opencv.core.Mat.empty方法的典型用法代码示例。如果您正苦于以下问题:Java Mat.empty方法的具体用法?Java Mat.empty怎么用?Java Mat.empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opencv.core.Mat
的用法示例。
在下文中一共展示了Mat.empty方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: analyzeObject
import org.opencv.core.Mat; //导入方法依赖的package包/类
/**
* Analyzes an object in preparation to search for the object in a frame.
* <p/>
* This method should be called in an initialize() method.
* Calling the analyzeObject method twice will overwrite the previous objectAnalysis.
* <p/>
* It is recommended to use a GFTT (Good Features To Track) detector for this phase.
*
* @param object Object image
* @return The object descriptor matrix to be piped into locateObject() later
*/
public ObjectAnalysis analyzeObject(Mat object) throws IllegalArgumentException {
Mat descriptors = new Mat();
MatOfKeyPoint keypoints = new MatOfKeyPoint();
Log.d("FTCVision", "Analyzing object...");
if (object == null || object.empty()) {
throw new IllegalArgumentException("Object image cannot be empty!");
}
//Detect object keypoints
detector.detect(object, keypoints);
//Extract object keypoints
extractor.compute(object, keypoints, descriptors);
return new ObjectAnalysis(keypoints, descriptors, object);
}
示例2: grabFrame
import org.opencv.core.Mat; //导入方法依赖的package包/类
private Mat grabFrame()
{
Mat frame = new Mat(); // empty mat
if (cap.isOpened())
{
try
{
cap.read(frame);
if (!frame.empty()) process(frame);
}
catch(Exception ex)
{
System.err.println("Error during image processing.");
}
}
return frame;
}
示例3: detectMany
import org.opencv.core.Mat; //导入方法依赖的package包/类
/**
*
* @Title: detectMany
* @Description: 检测多人图片,返回检测的人脸区域对象
* @param mImgSRC
* @return
* MatOfRect
*/
public static MatOfRect detectMany(Mat mImgSRC) {
if(mImgSRC.empty()) {
LOG.info("检测多人图片检测时没有找到图片");
return null;
}
// 人脸检测器文件的所在路径的文件夹名称数组
String [] pathKey = {ServletContextHolder.getOpenCVHaarcascades(), "haarcascade_frontalface_alt.xml"};
CascadeClassifier cascade = new CascadeClassifier(FileUtils.buildFilePath(pathKey));
if(cascade.empty()) {
LOG.info("人脸检测级联加载器为null");
return null;
}
// 记录搜索到的人脸区域
MatOfRect mOfRect = new MatOfRect();
// 用于计算缩放比例
int scaledWidth = mImgSRC.width();
detectManyObject(mImgSRC, cascade, mOfRect, scaledWidth);
if(mOfRect.toArray().length <= 0) {
LOG.info("没有检测到人脸...");
return null;
}
return mOfRect;
}
示例4: main
import org.opencv.core.Mat; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
final String input = "D:/workspace/SpotSpotter/src/pers/zylo117/spotspotter/image/4.jpg";
final String output = "D:/workspace/SpotSpotter/src/pers/zylo117/spotspotter/image/output4.jpg";
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
final Mat in = Imgcodecs.imread(input);
if (in.empty()) {
throw new Exception("no file");
}
final Mat out = LSD(in);
Imgcodecs.imwrite(output, out);
}
示例5: main
import org.opencv.core.Mat; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
final String input = "D:\\tmp\\5.jpg";
// final String output =
// "D:/workspace/SpotSpotter/src/pers/zylo117/spotspotter/image/output2.jpg";
System.loadLibrary("opencv_java330_64");
final Mat in = Imgcodecs.imread(input);
if (in.empty()) {
throw new Exception("no file");
}
final Mat mask = binaryzation_OpenCV(in, 300 * 0.6, true);
MatView.imshow(mask, "mask");
// Imgcodecs.imwrite(output, mask);
}
示例6: grabFrame
import org.opencv.core.Mat; //导入方法依赖的package包/类
private Mat grabFrame()
{
// init everything
Mat frame = new Mat();
// check if the capture is open
if (this.capture.isOpened())
{
try
{
// read the current frame
this.capture.read(frame);
// if the frame is not empty, process it
if (!frame.empty())
{
process(frame);
}
}
catch (Exception e)
{
// log the error
System.err.println("Exception during the image elaboration: " + e);
}
}
return frame;
}
示例7: grabFrame
import org.opencv.core.Mat; //导入方法依赖的package包/类
private Mat grabFrame() {
Mat frame = new Mat(); // empty mat
if (cap.isOpened()) {
try {
cap.read(frame);
if (!frame.empty()) process(frame);
} catch (Exception ex) {
System.err.println("Error during image processing.");
}
}
return frame;
}
示例8: grabImage
import org.opencv.core.Mat; //导入方法依赖的package包/类
public void grabImage(){
Mat frame = new Mat();
//connect
videoCapture = new VideoCapture(0);
isOpened = videoCapture.isOpened();
System.out.println("connected: " + isOpened);
//setSetting
videoCapture.set(Videoio.CV_CAP_PROP_FRAME_WIDTH, 1280);
videoCapture.set(Videoio.CV_CAP_PROP_FRAME_HEIGHT, 720);
//startGrab
isSucceed = videoCapture.grab();
System.out.println("started: " + String.valueOf(isSucceed));
if ((!isOpened) || (!isSucceed))
return;
System.out.println("------- START GRAB -------");
//Wait for camera starting
while (true){
videoCapture.read(frame);
if (!frame.empty())
break;
}
int frameNo = 0;
long startSysMillis = System.currentTimeMillis();
while (frameNo < 1000){
videoCapture.read(frame);
frameNo++;
}
System.out.println(frameNo + " frames in " + (System.currentTimeMillis() - startSysMillis) + " millis");
videoCapture.release(); // release device
System.out.println('\n' + "Done");
}
示例9: grabFrame
import org.opencv.core.Mat; //导入方法依赖的package包/类
/**
* Get a frame from the opened video stream (if any)
*
* @return the {@link Image} to show
*/
private Image grabFrame()
{
// init everything
Image imageToShow = null;
Mat frame = new Mat();
// check if the capture is open
if (this.capture.isOpened())
{
try
{
// read the current frame
this.capture.read(frame);
// if the frame is not empty, process it
if (!frame.empty())
{
// face detection
this.detectAndDisplay(frame);
// convert the Mat object (OpenCV) to Image (JavaFX)
imageToShow = mat2Image(frame);
}
}
catch (Exception e)
{
// log the (full) error
System.err.println("ERROR: " + e);
}
}
return imageToShow;
}
示例10: subspaceProject
import org.opencv.core.Mat; //导入方法依赖的package包/类
public static Mat subspaceProject(Mat W, Mat mean, Mat src) {
int n = src.rows();
int d = src.cols();
Mat X = new Mat();
Mat Y = new Mat();
src.convertTo(X, W.type());
if(!mean.empty()) {
for(int i = 0; i < n; i ++) {
Mat r_i = X.row(i);
Core.subtract(r_i, mean.reshape(1, 1), r_i);
}
}
Core.gemm(X, W, 1.0, new Mat(), 0.0, Y);
return Y;
}
示例11: subspaceReconstruct
import org.opencv.core.Mat; //导入方法依赖的package包/类
public static Mat subspaceReconstruct(Mat W, Mat mean, Mat src) {
int n = src.rows();
int d = src.cols();
Mat X = new Mat();
Mat Y = new Mat();
src.convertTo(Y, W.type());
Core.gemm(Y, W, 1.0, new Mat(), 0.0, X, 2);
if(!mean.empty()) {
for(int i = 0; i < n; i ++) {
Mat r_i = X.row(i);
Core.add(r_i, mean.reshape(1, 1), r_i);
}
}
return X;
}
示例12: cutOutImage
import org.opencv.core.Mat; //导入方法依赖的package包/类
/**
*
* @Title: cutOutImage
* @Description: 以Rect坐标裁剪图片
* @param src
* @param mOfRect
* @return
* List<Mat>
*/
public static List<Mat> cutOutImage(Mat src, MatOfRect mOfRect) {
List<Mat> outs = new ArrayList<Mat>();
if(src.empty() || mOfRect.toArray().length <= 0) {
return null;
}
int enlarge = 50; // 将图片的x,y坐标加大
for(Rect r : mOfRect.toArray()) {
int enlargeW = (r.x + enlarge) / r.x;
int enlargeH = (r.y + enlarge) / r.y;
r.x -= enlarge;
r.y -= enlarge;
r.width += (enlargeW * r.width);
r.height += (enlargeH * r.height);
// 确定人脸在图像中的整个边界,防止人脸在边框之外
if (r.x < 0) {
r.x = 0;
}
if (r.y < 0) {
r.y = 0;
}
if (r.x + r.width > src.cols()) {
r.x = src.cols() - r.width;
}
if (r.y + r.height > src.rows()) {
r.y = src.rows() - r.height;
}
Mat cutting = new Mat(src, r); // 裁剪图片
// System.out.println(cutting);
outs.add(cutting);
}
return outs;
}