本文整理汇总了Java中org.opencv.highgui.Highgui.imread方法的典型用法代码示例。如果您正苦于以下问题:Java Highgui.imread方法的具体用法?Java Highgui.imread怎么用?Java Highgui.imread使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opencv.highgui.Highgui
的用法示例。
在下文中一共展示了Highgui.imread方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FileUtil
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
public FileUtil(String sourceFileName, int length, int width) throws IOException{
this.length = length;
this.width = width;
this.sourceFileName = sourceFileName;
outputArray = new int[this.length][this.width];
sourceMat = Highgui.imread(this.sourceFileName);
for(String tempalteFileName : templateFileNames){
InputStream input = this.getClass().getResourceAsStream("/" + tempalteFileName);
FileOutputStream fos = new FileOutputStream(tempFileName);
byte[] b = new byte[1024];
while((input.read(b)) != -1){
fos.write(b);
}
input.close();
fos.close();
templateMat.add(Highgui.imread(tempFileName));
}
File file = new File(tempFileName);
file.delete();
Process();
}
示例2: main
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
/**
* Command-line interface.
* @param args unused here.
*/
public static void main(String[] args) {
// Load the OpenCV native library.
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
// Take a picture with the camera pi
String pictureId = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date());
PictureConfig pictureConfig = new PictureConfig("capture_" + pictureId, 640, 480);
pictureConfig.setVerticalFlip(true);
String filePath = CameraPi.takePicture(pictureConfig).getFilePath();
// Look for faces
Mat image = Highgui.imread(filePath);
Rect[] faces = FaceDetector.detectFaces(image);
Tools.log(String.format("%s faces detected", faces.length));
Tools.log("Input file path: " + filePath);
// Create a new picture, with detected faces
FaceDetector.surroundFaces(image, faces, "output_" + pictureId + ".jpg");
Tools.log("Output file: " + "output_" + pictureId + ".jpg");
}
示例3: onActivityResult
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PHOTO) {
if (resultCode == RESULT_OK) {
// new photo taken
// read the photo
im = Highgui.imread(dir.getAbsolutePath()+"/calibrate"+PHOTOS+".jpg");
// find corners in an asynctask because it is a heavy operation
new FindCornersTask(this).execute(im);
// boolean ret = Calib3d.findChessboardCorners(im, new Size(9,6), corners);
// Calib3d.drawChessboardCorners(im, new Size(9,6), corners, ret);
// save it
// Highgui.imwrite(dir.getAbsolutePath()+"/calibrate"+PHOTOS+"-drawn.jpg", im);
// insert it into the layout
// ImageView photo = (ImageView) findViewById(R.id.photo);
// Bitmap bmp = Bitmap.createBitmap(im.cols(), im.rows(), Bitmap.Config.ARGB_8888);
// org.opencv.android.Utils.matToBitmap(im,bmp);
// photo.setImageBitmap(bmp);
PHOTOS++;
}
}
}
示例4: main
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
public static void main(String[] args) {
// ָ��������ͼƬ·����������ļ�
String inputImagePath = identificate.class.getClassLoader().getResource("hf.jpg").getPath().substring(1);
String outputImageFile = "identificate.png";
String xmlPath = identificate.class.getClassLoader().getResource("cascade_storage.xml").getPath().substring(1);
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
CascadeClassifier faceDetector = new CascadeClassifier(xmlPath);
Mat image = Highgui.imread(inputImagePath);
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);
// ���������
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, 0, 255));
}
// д�뵽�ļ�
Highgui.imwrite(outputImageFile, image);
System.out.print("\nOK!");
}
示例5: readImageFromPath
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
public static Mat readImageFromPath(String filePath) throws IOException {
if (ReplicaUtils.isHDFS(filePath)) {
return ReplicaUtils.readFromHDFS(filePath);
}
else if (ReplicaUtils.isURL(filePath)) {
return ReplicaUtils.getImageContentFromURL(new URL(filePath));
}
else {
if (ReplicaUtils.fileExists(filePath)) {
return Highgui.imread(filePath, Highgui.CV_LOAD_IMAGE_ANYCOLOR);
}
else {
throw new IOException("Path '" + filePath + "' does not exist");
}
}
}
示例6: ImageReturn
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
public static void ImageReturn(String filename) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat img = Highgui.imread(filename);
// Mat scaledImg = new Mat();
int count = 0;
// Imgproc.resize(img,scaledImg ,new Size(320, 240));
for (int row = 337; row < 358; row++) {
for (int col = 339; col < 392; col++) {
// if (!(((row > 304) && (row < 356)) && ((col > 630) && (col < 668)))) {
count++;
System.out.println(img.get(row,col)[2]);
// System.out.println("Count:" + count);
// }
}
}
}
示例7: main
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
public static void main (String[] args) {
CVLoader.load();
// load the image
Mat img = Highgui.imread("data/topdown-9.png");
Mat equ = new Mat();
img.copyTo(equ);
Imgproc.blur(equ, equ, new Size(3, 3));
Imgproc.cvtColor(equ, equ, Imgproc.COLOR_BGR2YCrCb);
List<Mat> channels = new ArrayList<Mat>();
Core.split(equ, channels);
Imgproc.equalizeHist(channels.get(0), channels.get(0));
Core.merge(channels, equ);
Imgproc.cvtColor(equ, equ, Imgproc.COLOR_YCrCb2BGR);
Mat gray = new Mat();
Imgproc.cvtColor(equ, gray, Imgproc.COLOR_BGR2GRAY);
Mat grayOrig = new Mat();
Imgproc.cvtColor(img, grayOrig, Imgproc.COLOR_BGR2GRAY);
ImgWindow.newWindow(img);
ImgWindow.newWindow(equ);
ImgWindow.newWindow(gray);
ImgWindow.newWindow(grayOrig);
}
示例8: main
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
public static void main(String[] args) {
String filename = args[0];
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat original = Highgui.imread(filename);
if(original.empty()) {
System.out.println("Mat not successfully loaded.");
System.exit(1);
}
KoBoard board = new KoBoard(original);
saveImage(filename, original);
}
示例9: openImage
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
public static Mat openImage(String path) {
Mat img = Highgui.imread(path, Highgui.CV_LOAD_IMAGE_COLOR);
if(img.empty())
return null;
//Imgproc.cvtColor(img, img, Imgproc.COLOR_BGR2HSV);
return img;
}
示例10: imageToCSV
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
protected static String imageToCSV(CSVWriter writer, long id, String full, String path) {
String ext = Files.getFileExtension(path);
Mat src = Highgui.imread(full, Highgui.CV_LOAD_IMAGE_ANYCOLOR);
writer.writeNext(new String[]{String.valueOf(id), path, ext,
String.valueOf(src.size().height), String.valueOf(src.size().width),
null, null, null, null});
return ext;
}
示例11: run
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
public void run() {
System.out.println("\nRunning CopyImage");
// Create a face detector from the cascade file in the resources
// directory.
//CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("/lbpcascade_frontalface.xml").getPath());
// For now, just read the image that is in the directory with our java project file
Mat image = Highgui.imread("C:lena.jpg", Highgui.CV_LOAD_IMAGE_COLOR);
//Mat image = Highgui.imread("yellow-tote-top.jpg", Highgui.CV_LOAD_IMAGE_COLOR);
int srcRows = image.rows();
int srcCols = image.cols();
long imgData = image.dataAddr();
System.out.println("Source rows = " + srcRows + " Src columns = " + srcCols);
new LoadImage("C:dst1.jpg",image);
int loadedRows = image.rows();
int loadedCols = image.cols();
System.out.println("Loaded rows = " + loadedRows + " Loaded columns = " + loadedCols);
// 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";
// For now, just save a copy of the original image.
// Note: that this is also done in the LoadImage function.
String filename = "imageCopy.jpg";
System.out.println(String.format("Writing %s", filename));
Highgui.imwrite(filename, image);
}
示例12: setImagesForDatabaseEdit
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
private void setImagesForDatabaseEdit() {
for(int i = 0; i < faceImages.size(); i++) {
Mat m = Highgui.imread(thisPerson.getFacesFolderPath()+"/"+i+".jpg");
if(m != null) {
onFaceCaptured(m);
}
}
}
示例13: MatchHistogram
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
public MatchHistogram (String templatePath) {
Mat template = Highgui.imread(templatePath);
templateHistogram = histogram.extract(template);
String s = "";
for ( int i = 0; i < templateHistogram.length; ++i) {
s += templateHistogram[i];
}
}
示例14: main
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat img=Highgui.imread("testing/circle.png");
Imgproc.threshold(img, img, 35, 255, Imgproc.THRESH_BINARY);
Imgproc.cvtColor(img, img, Imgproc.COLOR_BGR2GRAY);
MassDetectionandObjectPriority a= new MassDetectionandObjectPriority(img, 255, 1);
Pair<int[],Integer> r=a.call();
System.out.println(Arrays.toString(r.getValue0()));
}
示例15: match
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
public double match (String path){
Mat img = Highgui.imread(path);
Mat imgResized = new Mat (SIZE,SIZE, img.type());
Imgproc.resize(img, imgResized, new Size(SIZE,SIZE));
double distance = 0;
for (int i = 0; i < SIZE; i++){
for (int j = 0; j < SIZE; j++){
if ((imgResized.get(i, j)[0] == 255) &&
(imgResized.get(i, j)[1] == 255) &&
(imgResized.get(i, j)[2] == 255)){
distance += PENALTY;
}
else{
distance += Math.pow (imgResized.get(i, j)[0] - templateResized.get(i, j)[0], 2) +
Math.pow (imgResized.get(i, j)[1] - templateResized.get(i, j)[1], 2) +
Math.pow (imgResized.get(i, j)[2] - templateResized.get(i, j)[2], 2);
}
}
}
return -distance;
}