本文整理了Java中org.opencv.imgproc.Imgproc.resize()
方法的一些代码示例,展示了Imgproc.resize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Imgproc.resize()
方法的具体详情如下:
包路径:org.opencv.imgproc.Imgproc
类名称:Imgproc
方法名:resize
[英]Resizes an image.
The function resize
resizes the image src
down to or up to the specified size.Note that the initial dst
type or size are not taken into account. Instead, the size and type are derived from the src
,dsize
,fx
, and fy
. If you want to resize src
so that it fits the pre-created dst
, you may call the function as follows: ``
// C++ code:
// explicitly specify dsize=dst.size(); fx and fy will be computed from that.
resize(src, dst, dst.size(), 0, 0, interpolation);
If you want to decimate the image by factor of 2 in each direction, you can call the function this way:
// specify fx and fy and let the function compute the destination image size.
resize(src, dst, Size(), 0.5, 0.5, interpolation);
To shrink an image, it will generally look best with CV_INTER_AREA interpolation, whereas to enlarge an image, it will generally look best with CV_INTER_CUBIC (slow) or CV_INTER_LINEAR (faster but still looks OK).
[中]调整图像的大小。
函数resize
将图像src
的大小调整到指定的大小。请注意,不考虑初始dst
类型或大小。相反,大小和类型是从src
、dsize
、fx
和fy
派生的。如果要调整src
的大小,使其适合预先创建的dst
,可以按如下方式调用该函数:``
//C++代码:
//显式指定dsize=dst。大小();fx和fy将由此计算。
调整大小(src,dst,dst.size(),0,0,插值);
如果要按每个方向的2倍抽取图像,可以通过以下方式调用该函数:
//指定fx和fy,并让函数计算目标图像大小。
调整大小(src、dst、Size()、0.5、0.5、插值);
要缩小图像,通常使用CV_INTER_区域插值效果最好,而要放大图像,通常使用CV_INTER_立方体(慢速)或CV_INTER_线性插值效果最好(速度更快,但看起来仍然正常)。
代码示例来源:origin: RaiMan/SikuliX2
public Mat getResizedMat(double factor) {
Mat newMat = getContent();
if (isValid()) {
newMat = getNewMat();
Size newS = new Size(w * factor, h * factor);
Imgproc.resize(getContent(), newMat, newS, 0, 0, Imgproc.INTER_AREA);
}
return newMat;
}
代码示例来源:origin: RaiMan/SikuliX2
sizeBase = new Size(this.mBase.cols() / rfactor, this.mBase.rows() / rfactor);
sizePattern = new Size(target.getContent().cols() / rfactor, target.getContent().rows() / rfactor);
Imgproc.resize(this.mBase, mBase, sizeBase, 0, 0, Imgproc.INTER_AREA);
Imgproc.resize(target.getContentBGR(), mPattern, sizePattern, 0, 0, Imgproc.INTER_AREA);
Picture pPattern = new Picture(mPattern);
if (target.hasMask()) {
Imgproc.resize(target.getMask(), mPatternMask, sizePattern, 0, 0, Imgproc.INTER_AREA);
pPattern.setMask(mPatternMask);
代码示例来源:origin: nroduit/Weasis
public static ImageCV scale(Mat source, Dimension dim) {
if (Objects.requireNonNull(dim).width < 1 || dim.height < 1) {
throw new IllegalArgumentException("Unsupported size: " + dim);
}
ImageCV dstImg = new ImageCV();
Imgproc.resize(Objects.requireNonNull(source), dstImg, new Size(dim.getWidth(), dim.getHeight()));
return dstImg;
}
代码示例来源:origin: nroduit/Weasis
public static ImageCV scale(Mat source, Dimension dim, Integer interpolation) {
if (interpolation == null || interpolation < Imgproc.INTER_NEAREST || interpolation > Imgproc.INTER_LANCZOS4) {
return scale(source, dim);
}
if (Objects.requireNonNull(dim).width < 1 || dim.height < 1) {
throw new IllegalArgumentException("Unsupported size: " + dim);
}
ImageCV dstImg = new ImageCV();
Imgproc.resize(Objects.requireNonNull(source), dstImg, new Size(dim.getWidth(), dim.getHeight()), 0, 0,
interpolation);
return dstImg;
}
代码示例来源:origin: openpnp/openpnp
private static Mat scale(Mat mat, int scaleWidth, int scaleHeight) {
if (scaleWidth == 0 || scaleHeight == 0) {
return mat;
}
Mat dst = new Mat();
Imgproc.resize(mat, dst, new Size(scaleWidth, scaleHeight));
mat.release();
return dst;
}
代码示例来源:origin: us.ihmc/IHMCPerception
public static void resizeImage(Mat image, double scaleFactor)
{
Imgproc.resize(image, image, new Size((int) (image.width() * scaleFactor), (int) (image.height() * scaleFactor)));
}
}
代码示例来源:origin: us.ihmc/ihmc-perception
public static void resizeImage(Mat image, double scaleFactor)
{
Imgproc.resize(image, image, new Size((int) (image.width() * scaleFactor), (int) (image.height() * scaleFactor)));
}
}
代码示例来源:origin: nroduit/Weasis
public static ImageCV buildThumbnail(PlanarImage source, Dimension iconDim, boolean keepRatio) {
Objects.requireNonNull(source);
if (Objects.requireNonNull(iconDim).width < 1 || iconDim.height < 1) {
throw new IllegalArgumentException("Unsupported size: " + iconDim);
}
final double scale = Math.min(iconDim.getHeight() / source.height(), iconDim.getWidth() / source.width());
if (scale >= 1.0) {
return source.toImageCV();
}
if (scale < 0.005) {
return null; // Image is too large to be converted
}
Size dim = keepRatio ? new Size((int) (scale * source.width()), (int) (scale * source.height()))
: new Size(iconDim.width, iconDim.height);
Mat srcImg = Objects.requireNonNull(source).toMat();
ImageCV dstImg = new ImageCV();
Imgproc.resize(srcImg, dstImg, dim, 0, 0, Imgproc.INTER_AREA);
return dstImg;
}
代码示例来源:origin: io.github.martinschneider/justtestlah-core
/**
* @param image the {@link Mat} to scale
* @param scaleFactor the scale factor (<1 will scale down, >1 will scale up, 1 = 100%)
* @return a {@link Mat} which is a version of the original image scaled by the given factor
*/
public Mat scaleImage(Mat image, double scaleFactor) {
Mat resizedImage = new Mat();
Size sz = new Size(image.width() * scaleFactor, image.height() * scaleFactor);
Imgproc.resize(image, resizedImage, sz);
return resizedImage;
}
}
代码示例来源:origin: jdye64/nifi-addons
@Override
public void process(InputStream inputStream, OutputStream outputStream) throws IOException {
try {
int zoomingFactor = context.getProperty(ZOOMING_FACTOR).asInteger();
BufferedImage image = ImageIO.read(inputStream);
byte[] pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
Mat source = new Mat(image.getHeight(), image.getWidth(), Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
source.put(0, 0, pixels);
Mat destination = new Mat(source.rows() * zoomingFactor, source.cols() * zoomingFactor, source.type());
Imgproc.resize(source, destination, destination.size(), zoomingFactor, zoomingFactor, Imgproc.INTER_NEAREST);
MatOfByte bytemat = new MatOfByte();
Imgcodecs.imencode(".png", destination, bytemat);
pixels = bytemat.toArray();
outputStream.write(pixels);
} catch (Exception ex) {
getLogger().error(ex.getMessage());
ex.printStackTrace();
}
}
});
代码示例来源:origin: tz28/Chinese-number-gestures-recognition
private Bitmap scaleImage(Bitmap bitmap, int width, int height)
{
Mat src = new Mat();
Mat dst = new Mat();
Utils.bitmapToMat(bitmap, src);
//new Size(width, height)
Imgproc.resize(src, dst, new Size(width,height),0,0,Imgproc.INTER_AREA);
Bitmap bitmap1 = Bitmap.createBitmap(dst.cols(),dst.rows(),Bitmap.Config.RGB_565);
Utils.matToBitmap(dst, bitmap1);
return bitmap1;
}
代码示例来源:origin: nroduit/Weasis
public static boolean writeThumbnail(Mat source, File file, int maxSize) {
try {
final double scale =
Math.min(maxSize / (double) source.height(), (double) maxSize / source.width());
if (scale < 1.0) {
Size dim = new Size((int) (scale * source.width()), (int) (scale * source.height()));
Mat thumbnail = new Mat();
Imgproc.resize(source, thumbnail, dim, 0, 0, Imgproc.INTER_AREA);
MatOfInt map = new MatOfInt(Imgcodecs.IMWRITE_JPEG_QUALITY, 80);
return Imgcodecs.imwrite(file.getPath(), thumbnail, map);
}
return false;
} catch (OutOfMemoryError | CvException e) {
LOGGER.error("Writing thumbnail", e); //$NON-NLS-1$
delete(file);
return false;
}
}
代码示例来源:origin: SOFTPOWER1991/OpenCVCheck
/**
* 特征保存
*
* @param image Mat
* @param rect 人脸信息
* @param fileName 文件名字
* @return 保存是否成功
*/
public boolean saveImage(Mat image, Rect rect, String fileName) {
try {
// 原图置灰
Mat grayMat = new Mat();
Imgproc.cvtColor(image, grayMat, Imgproc.COLOR_BGR2GRAY);
// 把检测到的人脸重新定义大小后保存成文件
Mat sub = grayMat.submat(rect);
Mat mat = new Mat();
Size size = new Size(100, 100);
Imgproc.resize(sub, mat, size);
return Highgui.imwrite(getFilePath(fileName), mat);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
代码示例来源:origin: ytai/IOIOPlotter
private void load() throws IOException {
InputStream stream = resolveUri(context_, uri_);
Mat buf = streamToMat(stream);
srcImage_ = Highgui.imdecode(buf, Highgui.CV_LOAD_IMAGE_GRAYSCALE);
float scale = LINE_WIDTH_TO_IMAGE_WIDTH / srcImage_.cols();
imageScaledToPreview_ = new Mat();
imageResidue_ = new Mat();
Imgproc.resize(srcImage_, imageScaledToPreview_, new Size(), scale, scale,
Imgproc.INTER_AREA);
previewImage_ = new Mat(imageScaledToPreview_.size(), CvType.CV_8UC1);
previewBitmap_ = Bitmap.createBitmap(imageScaledToPreview_.cols(),
imageScaledToPreview_.rows(), Config.ARGB_8888);
}
代码示例来源:origin: ytai/IOIOPlotter
private void clear() {
// Resize to native resolution divided by blur factor.
float scale = LINE_WIDTH_TO_IMAGE_WIDTH / blur_ / srcImage_.cols();
Imgproc.resize(srcImage_, imageResidue_, new Size(), scale, scale, Imgproc.INTER_AREA);
// Negative.
final Mat scalar = new Mat(1, 1, CvType.CV_64FC1).setTo(new Scalar(255));
Core.subtract(scalar, imageResidue_, imageResidue_);
// Convert to S16.
imageResidue_.convertTo(imageResidue_, CvType.CV_16SC1);
// Full scale is now blur * GRAY_RESOLUTION.
Core.multiply(imageResidue_, new Scalar(blur_ * GRAY_RESOLUTION / 255), imageResidue_);
// Clear map.
curves_.clear();
kernelFactory_.setDimensions(imageResidue_.width(), imageResidue_.height());
}
代码示例来源:origin: us.ihmc/ihmc-perception
Mat image = OpenCVTools.convertBufferedImageToMat(bufferedImage);
if (DEBUG) conversion = timer.lap();
Imgproc.resize(image, image, new Size((int) (image.width() * scaleFactor), (int) (image.height() * scaleFactor)));
if (DEBUG) resize = timer.lap();
cascadeClassifierForFaces.detectMultiScale(image, faces);
代码示例来源:origin: us.ihmc/ihmc-perception
public boolean findChessCornerRobustForExtremePitch(Mat original, Size patternSize, MatOfPoint2f corners, int flags, boolean attemptExtremePitchDetection)
{
boolean success = Calib3d.findChessboardCorners(original, boardInnerCrossPattern, corners, flags);
if (success)
{
return success;
}
if(attemptExtremePitchDetection)
{
//try stretch image vertically
Mat resizeMat = new Mat();
Imgproc.resize(original, resizeMat, new Size(original.width(), original.height() * 2));
if (Calib3d.findChessboardCorners(resizeMat, boardInnerCrossPattern, corners, flags))
{
Point[] cornerArray = corners.toArray();
for (Point p : cornerArray)
p.y /= 2;
corners.fromArray(cornerArray);
return true;
}
}
return false;
}
代码示例来源:origin: us.ihmc/IHMCPerception
Mat image = OpenCVTools.convertBufferedImageToMat(bufferedImage);
if (DEBUG) conversion = timer.lap();
Imgproc.resize(image, image, new Size((int) (image.width() * scaleFactor), (int) (image.height() * scaleFactor)));
if (DEBUG) resize = timer.lap();
cascadeClassifierForFaces.detectMultiScale(image, faces);
代码示例来源:origin: us.ihmc/IHMCPerception
public boolean findChessCornerRobustForExtremePitch(Mat original, Size patternSize, MatOfPoint2f corners, int flags, boolean attemptExtremePitchDetection)
{
boolean success = Calib3d.findChessboardCorners(original, boardInnerCrossPattern, corners, flags);
if (success)
{
return success;
}
if(attemptExtremePitchDetection)
{
//try stretch image vertically
Mat resizeMat = new Mat();
Imgproc.resize(original, resizeMat, new Size(original.width(), original.height() * 2));
if (Calib3d.findChessboardCorners(resizeMat, boardInnerCrossPattern, corners, flags))
{
Point[] cornerArray = corners.toArray();
for (Point p : cornerArray)
p.y /= 2;
corners.fromArray(cornerArray);
return true;
}
}
return false;
}
代码示例来源:origin: JavaOpenCVBook/code
Imgproc.resize(background, resizedBackground, disparityImage.size());
内容来源于网络,如有侵权,请联系作者删除!