OpenCV
成都創(chuàng)新互聯(lián)公司于2013年開(kāi)始,先為維西等服務(wù)建站,維西等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢(xún)服務(wù)。為維西企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。
整個(gè)項(xiàng)目的結(jié)構(gòu)圖:
編寫(xiě)DetectFaceDemo.java,代碼如下:
[java] view
plaincopyprint?
package com.njupt.zhb.test;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.objdetect.CascadeClassifier;
//
// Detects faces in an image, draws boxes around them, and writes the results
// to "faceDetection.png".
//
public class DetectFaceDemo {
public void run() {
System.out.println("\nRunning DetectFaceDemo");
System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath());
// Create a face detector from the cascade file in the resources
// directory.
//CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath());
//Mat image = Highgui.imread(getClass().getResource("lena.png").getPath());
//注意:源程序的路徑會(huì)多打印一個(gè)‘/’,因此總是出現(xiàn)如下錯(cuò)誤
/*
* Detected 0 faces Writing faceDetection.png libpng warning: Image
* width is zero in IHDR libpng warning: Image height is zero in IHDR
* libpng error: Invalid IHDR data
*/
//因此,我們將第一個(gè)字符去掉
String xmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1);
CascadeClassifier faceDetector = new CascadeClassifier(xmlfilePath);
Mat image = Highgui.imread(getClass().getResource("we.jpg").getPath().substring(1));
// Detect faces in the image.
// MatOfRect is a special container class for Rect.
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);
System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));
// Draw a bounding box around each face.
for (Rect rect : faceDetections.toArray()) {
Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
}
// Save the visualized detection.
String filename = "faceDetection.png";
System.out.println(String.format("Writing %s", filename));
Highgui.imwrite(filename, image);
}
}
package com.njupt.zhb.test;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.objdetect.CascadeClassifier;
//
// Detects faces in an image, draws boxes around them, and writes the results
// to "faceDetection.png".
//
public class DetectFaceDemo {
public void run() {
System.out.println("\nRunning DetectFaceDemo");
System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath());
// Create a face detector from the cascade file in the resources
// directory.
//CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath());
//Mat image = Highgui.imread(getClass().getResource("lena.png").getPath());
//注意:源程序的路徑會(huì)多打印一個(gè)‘/’,因此總是出現(xiàn)如下錯(cuò)誤
/*
* Detected 0 faces Writing faceDetection.png libpng warning: Image
* width is zero in IHDR libpng warning: Image height is zero in IHDR
* libpng error: Invalid IHDR data
*/
//因此,我們將第一個(gè)字符去掉
String xmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1);
CascadeClassifier faceDetector = new CascadeClassifier(xmlfilePath);
Mat image = Highgui.imread(getClass().getResource("we.jpg").getPath().substring(1));
// Detect faces in the image.
// MatOfRect is a special container class for Rect.
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);
System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));
// Draw a bounding box around each face.
for (Rect rect : faceDetections.toArray()) {
Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
}
// Save the visualized detection.
String filename = "faceDetection.png";
System.out.println(String.format("Writing %s", filename));
Highgui.imwrite(filename, image);
}
}
3.編寫(xiě)測(cè)試類(lèi):
[java] view
plaincopyprint?
package com.njupt.zhb.test;
public class TestMain {
public static void main(String[] args) {
System.out.println("Hello, OpenCV");
// Load the native library.
System.loadLibrary("opencv_java246");
new DetectFaceDemo().run();
}
}
//運(yùn)行結(jié)果:
//Hello, OpenCV
//
//Running DetectFaceDemo
///E:/eclipse_Jee/workspace/JavaOpenCV246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml
//Detected 8 faces
//Writing faceDetection.png
package com.njupt.zhb.test;
public class TestMain {
public static void main(String[] args) {
System.out.println("Hello, OpenCV");
// Load the native library.
System.loadLibrary("opencv_java246");
new DetectFaceDemo().run();
}
}
//運(yùn)行結(jié)果:
//Hello, OpenCV
//
//Running DetectFaceDemo
///E:/eclipse_Jee/workspace/JavaOpenCV246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml
//Detected 8 faces
//Writing faceDetection.png
java是編程語(yǔ)言里比較難學(xué)的一門(mén),如果有心從事編程方向的工作,最好到專(zhuān)業(yè)機(jī)構(gòu)學(xué)習(xí)并有更多的項(xiàng)目實(shí)踐,更貼近市場(chǎng),這樣更有利于將來(lái)的發(fā)展。
解決方法:
1、可以電腦下載IVMS-4200客戶(hù)端對(duì)攝像頭進(jìn)行校時(shí)。
2、單個(gè)設(shè)備校時(shí):打開(kāi)IVMS-4200客戶(hù)端,在主預(yù)覽界面,選擇對(duì)應(yīng)的需要校時(shí)的畫(huà)面,鼠標(biāo)右擊,點(diǎn)擊“校時(shí)”即可。 【 注意】:電腦的時(shí)間要正確。
3、多個(gè)批量校時(shí):點(diǎn)開(kāi)IVMS-4200最上方工具按鈕,選擇批量校時(shí),然后在彈出的界面選擇需要批量校時(shí)的設(shè)備,點(diǎn)擊確定,即可完成對(duì)多個(gè)設(shè)備的校時(shí)。
4、自動(dòng)校時(shí):進(jìn)入IVMS-4200客戶(hù)端,控制面板-系統(tǒng)配置-常用界面,啟用自動(dòng)校時(shí),設(shè)置校時(shí)時(shí)間,可以對(duì)添加到客戶(hù)端的所有設(shè)備進(jìn)行自動(dòng)校時(shí)。
首先,你需要把Demo代碼貼出來(lái),其次,一般Demo示例都是main方法直接運(yùn)行,也可能是tomcat啟動(dòng),最后你應(yīng)該找對(duì)應(yīng)Demo的說(shuō)明文檔,一般Demo都有注釋或說(shuō)明文檔的