本文整理匯總了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;
}