init - 初始化项目

This commit is contained in:
Lee Nony
2022-05-06 01:58:53 +08:00
commit 90a5cc7cb6
6772 changed files with 2837787 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
package org.opencv.test.imgcodecs;
import org.opencv.core.MatOfByte;
import org.opencv.core.MatOfInt;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.test.OpenCVTestCase;
import org.opencv.test.OpenCVTestRunner;
public class ImgcodecsTest extends OpenCVTestCase {
public void testImdecode() {
fail("Not yet implemented");
}
public void testImencodeStringMatListOfByte() {
MatOfByte buff = new MatOfByte();
assertEquals(0, buff.total());
assertTrue( Imgcodecs.imencode(".jpg", gray127, buff) );
assertFalse(0 == buff.total());
}
public void testImencodeStringMatListOfByteListOfInteger() {
MatOfInt params40 = new MatOfInt(Imgcodecs.IMWRITE_JPEG_QUALITY, 40);
MatOfInt params90 = new MatOfInt(Imgcodecs.IMWRITE_JPEG_QUALITY, 90);
/* or
MatOfInt params = new MatOfInt();
params.fromArray(Imgcodecs.IMWRITE_JPEG_QUALITY, 40);
*/
MatOfByte buff40 = new MatOfByte();
MatOfByte buff90 = new MatOfByte();
assertTrue( Imgcodecs.imencode(".jpg", rgbLena, buff40, params40) );
assertTrue( Imgcodecs.imencode(".jpg", rgbLena, buff90, params90) );
assertTrue(buff40.total() > 0);
assertTrue(buff40.total() < buff90.total());
}
public void testImreadString() {
dst = Imgcodecs.imread(OpenCVTestRunner.LENA_PATH);
assertFalse(dst.empty());
assertEquals(3, dst.channels());
assertTrue(512 == dst.cols());
assertTrue(512 == dst.rows());
}
public void testImreadStringInt() {
dst = Imgcodecs.imread(OpenCVTestRunner.LENA_PATH, 0);
assertFalse(dst.empty());
assertEquals(1, dst.channels());
assertTrue(512 == dst.cols());
assertTrue(512 == dst.rows());
}
public void testImwriteStringMat() {
fail("Not yet implemented");
}
public void testImwriteStringMatListOfInteger() {
fail("Not yet implemented");
}
}

View File

@@ -0,0 +1,32 @@
//
// Mat+UIImage.h
//
// Created by Giles Payne on 2020/03/03.
//
#pragma once
#ifdef __cplusplus
#import "opencv2/core.hpp"
#else
#define CV_EXPORTS
#endif
#import "Mat.h"
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
CV_EXPORTS @interface Mat (Converters)
-(CGImageRef)toCGImage CF_RETURNS_RETAINED;
-(instancetype)initWithCGImage:(CGImageRef)image;
-(instancetype)initWithCGImage:(CGImageRef)image alphaExist:(BOOL)alphaExist;
-(UIImage*)toUIImage;
-(instancetype)initWithUIImage:(UIImage*)image;
-(instancetype)initWithUIImage:(UIImage*)image alphaExist:(BOOL)alphaExist;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,44 @@
//
// Mat+UIImage.mm
//
// Created by Giles Payne on 2020/03/03.
//
#import "Mat+Converters.h"
#import <opencv2/imgcodecs/ios.h>
@implementation Mat (Converters)
-(CGImageRef)toCGImage {
return MatToCGImage(self.nativeRef);
}
-(instancetype)initWithCGImage:(CGImageRef)image {
return [self initWithCGImage:image alphaExist:NO];
}
-(instancetype)initWithCGImage:(CGImageRef)image alphaExist:(BOOL)alphaExist {
self = [self init];
if (self) {
CGImageToMat(image, self.nativeRef, (bool)alphaExist);
}
return self;
}
-(UIImage*)toUIImage {
return MatToUIImage(self.nativeRef);
}
-(instancetype)initWithUIImage:(UIImage*)image {
return [self initWithUIImage:image alphaExist:NO];
}
-(instancetype)initWithUIImage:(UIImage*)image alphaExist:(BOOL)alphaExist {
self = [self init];
if (self) {
UIImageToMat(image, self.nativeRef, (bool)alphaExist);
}
return self;
}
@end

View File

@@ -0,0 +1,32 @@
//
// Mat+Converters.h
//
// Created by Masaya Tsuruta on 2020/10/08.
//
#pragma once
#ifdef __cplusplus
#import "opencv2/core.hpp"
#else
#define CV_EXPORTS
#endif
#import "Mat.h"
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
NS_ASSUME_NONNULL_BEGIN
CV_EXPORTS @interface Mat (Converters)
-(CGImageRef)toCGImage CF_RETURNS_RETAINED;
-(instancetype)initWithCGImage:(CGImageRef)image;
-(instancetype)initWithCGImage:(CGImageRef)image alphaExist:(BOOL)alphaExist;
-(NSImage*)toNSImage;
-(instancetype)initWithNSImage:(NSImage*)image;
-(instancetype)initWithNSImage:(NSImage*)image alphaExist:(BOOL)alphaExist;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,44 @@
//
// Mat+Converters.mm
//
// Created by Masaya Tsuruta on 2020/10/08.
//
#import "Mat+Converters.h"
#import <opencv2/imgcodecs/macosx.h>
@implementation Mat (Converters)
-(CGImageRef)toCGImage {
return MatToCGImage(self.nativeRef);
}
-(instancetype)initWithCGImage:(CGImageRef)image {
return [self initWithCGImage:image alphaExist:NO];
}
-(instancetype)initWithCGImage:(CGImageRef)image alphaExist:(BOOL)alphaExist {
self = [self init];
if (self) {
CGImageToMat(image, self.nativeRef, (bool)alphaExist);
}
return self;
}
-(NSImage*)toNSImage {
return MatToNSImage(self.nativeRef);
}
-(instancetype)initWithNSImage:(NSImage*)image {
return [self initWithNSImage:image alphaExist:NO];
}
-(instancetype)initWithNSImage:(NSImage*)image alphaExist:(BOOL)alphaExist {
self = [self init];
if (self) {
NSImageToMat(image, self.nativeRef, (bool)alphaExist);
}
return self;
}
@end

View File

@@ -0,0 +1,50 @@
//
// Imgcodecs.swift
//
// Created by Giles Payne on 2020/02/10.
//
import XCTest
import OpenCV
class ImgcodecsTest: OpenCVTestCase {
let LENA_PATH = Bundle(for: ImgcodecsTest.self).path(forResource:"lena", ofType:"png", inDirectory:"resources")!
func testImencodeStringMatListOfByte() {
var buff = [UInt8]()
XCTAssert(Imgcodecs.imencode(ext: ".jpg", img: gray127, buf: &buff))
XCTAssertFalse(0 == buff.count)
}
func testImencodeStringMatListOfByteListOfInteger() {
let params40:[Int32] = [ImwriteFlags.IMWRITE_JPEG_QUALITY.rawValue, 40]
let params90:[Int32] = [ImwriteFlags.IMWRITE_JPEG_QUALITY.rawValue, 90]
var buff40 = [UInt8]()
var buff90 = [UInt8]()
XCTAssert(Imgcodecs.imencode(ext: ".jpg", img: rgbLena, buf: &buff40, params: params40))
XCTAssert(Imgcodecs.imencode(ext: ".jpg", img: rgbLena, buf: &buff90, params: params90))
XCTAssert(buff40.count > 0)
XCTAssert(buff40.count < buff90.count)
}
func testImreadString() {
dst = Imgcodecs.imread(filename: LENA_PATH)
XCTAssertFalse(dst.empty())
XCTAssertEqual(3, dst.channels())
XCTAssert(512 == dst.cols())
XCTAssert(512 == dst.rows())
}
func testImreadStringInt() {
dst = Imgcodecs.imread(filename: LENA_PATH, flags: 0)
XCTAssertFalse(dst.empty());
XCTAssertEqual(1, dst.channels());
XCTAssert(512 == dst.cols());
XCTAssert(512 == dst.rows());
}
}