本文整理汇总了Java中org.opencv.imgproc.Imgproc.cvtColor方法的典型用法代码示例。如果您正苦于以下问题:Java Imgproc.cvtColor方法的具体用法?Java Imgproc.cvtColor怎么用?Java Imgproc.cvtColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opencv.imgproc.Imgproc
的用法示例。
在下文中一共展示了Imgproc.cvtColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: skinDetection
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public Mat skinDetection(Mat src) {
// define the upper and lower boundaries of the HSV pixel
// intensities to be considered 'skin'
Scalar lower = new Scalar(0, 48, 80);
Scalar upper = new Scalar(20, 255, 255);
// Convert to HSV
Mat hsvFrame = new Mat(src.rows(), src.cols(), CvType.CV_8U, new Scalar(3));
Imgproc.cvtColor(src, hsvFrame, Imgproc.COLOR_RGB2HSV, 3);
// Mask the image for skin colors
Mat skinMask = new Mat(hsvFrame.rows(), hsvFrame.cols(), CvType.CV_8U, new Scalar(3));
Core.inRange(hsvFrame, lower, upper, skinMask);
// currentSkinMask = new Mat(hsvFrame.rows(), hsvFrame.cols(), CvType.CV_8U, new Scalar(3));
// skinMask.copyTo(currentSkinMask);
// apply a series of erosions and dilations to the mask
// using an elliptical kernel
final Size kernelSize = new Size(11, 11);
final Point anchor = new Point(-1, -1);
final int iterations = 2;
Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, kernelSize);
Imgproc.erode(skinMask, skinMask, kernel, anchor, iterations);
Imgproc.dilate(skinMask, skinMask, kernel, anchor, iterations);
// blur the mask to help remove noise, then apply the
// mask to the frame
final Size ksize = new Size(3, 3);
Mat skin = new Mat(skinMask.rows(), skinMask.cols(), CvType.CV_8U, new Scalar(3));
Imgproc.GaussianBlur(skinMask, skinMask, ksize, 0);
Core.bitwise_and(src, src, skin, skinMask);
return skin;
}
示例2: doCanny
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
* Apply Canny
*
* @param frame the current frame
* @return an image elaborated with Canny
*/
private Mat doCanny(Mat frame) {
// init
Mat grayImage = new Mat();
Mat detectedEdges = new Mat();
// convert to grayscale
Imgproc.cvtColor(frame, grayImage, Imgproc.COLOR_BGR2GRAY);
// reduce noise with a 3x3 kernel
Imgproc.blur(grayImage, detectedEdges, new Size(3, 3));
// canny detector, with ratio of lower:upper threshold of 3:1
Imgproc.Canny(detectedEdges, detectedEdges, threshold.getValue(), threshold.getValue() * 3);
// using Canny's output as a mask, display the result
Mat dest = new Mat();
frame.copyTo(dest, detectedEdges);
return dest;
}
示例3: rgba
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
@Override
public Mat rgba() {
if (mPreviewFormat == ImageFormat.NV21)
Imgproc.cvtColor(mYuvFrameData, mRgba, Imgproc.COLOR_YUV2RGBA_NV21, 4);
else if (mPreviewFormat == ImageFormat.YV12)
Imgproc.cvtColor(mYuvFrameData, mRgba, Imgproc.COLOR_YUV2RGB_I420, 4); // COLOR_YUV2RGBA_YV12 produces inverted colors
else
throw new IllegalArgumentException("Preview Format can be NV21 or YV12");
return mRgba;
}
示例4: conv_Mat
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
private Mat conv_Mat(BufferedImage img) {
byte[] data = ((DataBufferByte) img.getRaster().getDataBuffer()).getData();
Mat mat = new Mat(img.getHeight(), img.getWidth(), CvType.CV_8UC3);
mat.put(0, 0, data);
Mat mat1 = new Mat(img.getHeight(), img.getWidth(), CvType.CV_8UC3);
Imgproc.cvtColor(mat, mat1, Imgproc.COLOR_RGB2HSV);
return mat1;
}
开发者ID:javaspecial,项目名称:Face-detection-and-recognition-desktop-application,代码行数:10,代码来源:FaceRecognizeFrame.java
示例5: process
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
private void process(Mat f)
{
// grayscale toggle
if (grayscaleToggle.isSelected()) Imgproc.cvtColor(f, f, Imgproc.COLOR_BGR2GRAY);
// add image to frame
if (thenkToggle.isSelected() && thenkMat != null)
{
Rect roi = new Rect(f.cols()-thenkMat.cols(), f.rows()-thenkMat.rows(), thenkMat.cols(), thenkMat.rows());
Mat thenkROI = f.submat(roi);
Core.addWeighted(thenkROI, 1.0, thenkMat, 1.0, 0.0, thenkROI);
}
}
示例6: HarrisCorner
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
void HarrisCorner() {
Mat grayMat = new Mat();
Mat corners = new Mat();
//Converting the image to grayscale
Imgproc.cvtColor(originalMat, grayMat, Imgproc.COLOR_BGR2GRAY);
Mat tempDst = new Mat();
//finding contours
Imgproc.cornerHarris(grayMat, tempDst, 2, 3, 0.04);
//Normalizing harris corner's output
Mat tempDstNorm = new Mat();
Core.normalize(tempDst, tempDstNorm, 0, 255, Core.NORM_MINMAX);
Core.convertScaleAbs(tempDstNorm, corners);
//Drawing corners on a new image
Random r = new Random();
for (int i = 0; i < tempDstNorm.cols(); i++) {
for (int j = 0; j < tempDstNorm.rows(); j++) {
double[] value = tempDstNorm.get(j, i);
if (value[0] > 150)
Imgproc.circle(corners, new Point(i, j), 5, new Scalar(r.nextInt(255)), 2);
}
}
//Converting Mat back to Bitmap
Utils.matToBitmap(corners, currentBitmap);
imageView.setImageBitmap(currentBitmap);
}
示例7: findRectangle
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void findRectangle() {
Imgproc.cvtColor(originalImage, image, Imgproc.COLOR_BGR2GRAY);
setFilter();
this.rects.clear();
//Find Contours
Imgproc.findContours(image, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE, new Point(0, 0));
//For conversion later on
MatOfPoint2f approxCurve = new MatOfPoint2f();
//For each contour found
for (int i = 0; i < contours.size(); i++) {
//Convert contours from MatOfPoint to MatOfPoint2f
MatOfPoint2f contour2f = new MatOfPoint2f(contours.get(i).toArray());
//Processing on mMOP2f1 which is in type MatOfPoint2f
double approxDistance = Imgproc.arcLength(contour2f, true) * 0.02;
if (approxDistance > 1) {
//Find Polygons
Imgproc.approxPolyDP(contour2f, approxCurve, approxDistance, true);
//Convert back to MatOfPoint
MatOfPoint points = new MatOfPoint(approxCurve.toArray());
//Rectangle Checks - Points, area, convexity
if (points.total() == 4 && Math.abs(Imgproc.contourArea(points)) > 1000 && Imgproc.isContourConvex(points)) {
double cos = 0;
double mcos = 0;
for (int sc = 2; sc < 5; sc++) {
// TO-DO Figure a way to check angle
if (cos > mcos) {
mcos = cos;
}
}
if (mcos < 0.3) {
// Get bounding rect of contour
Rect rect = Imgproc.boundingRect(points);
// if (Math.abs(rect.height - rect.width) < 1000) {
System.out.println(i + "| x: " + rect.x + " + width("+rect.width+"), y: " + rect.y + "+ width("+rect.height+")");
rects.add(rect);
Core.rectangle(originalImage, rect.tl(), rect.br(), new Scalar(20, 20, 20), -1, 4, 0);
Imgproc.drawContours(originalImage, contours, i, new Scalar(0, 255, 0, .8), 2);
// Highgui.imwrite("detected_layers"+i+".png", originalImage);
// }
}
}
}
}
// Pass raw parameters
ImageDetection id = new ImageDetection();
HyperTextBuilder.rects = this.rects;
HyperTextBuilder.rect_height = this.HEIGHT;
HyperTextBuilder.rect_width = this.WIDTH;
id.setData(Utility.matToBufferedImage(originalImage));
}
示例8: leviRedFilter
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void leviRedFilter (Mat input, Mat mask, double threshold){
Imgproc.cvtColor(input, input, Imgproc.COLOR_RGB2Lab);
Imgproc.GaussianBlur(input,input,new Size(3,3),0);
Core.split(input, channels);
Imgproc.threshold(channels.get(1), mask, threshold, 255, Imgproc.THRESH_BINARY);
for(int i=0;i<channels.size();i++){
channels.get(i).release();
}
}
示例9: executar
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void executar(String output1, String output2){
int height1 = original.height();
int width1 = original.width();
Mat imgCinza = new Mat(height1, width1, original.type());
for (int h = 1; h < height1 - 1; h++) {
for (int w = 1; w < width1 - 1; w++) {
int cor = getMedianaCinza(h, w);
double[] tom = {cor, cor, cor};
imgCinza.put(h, w, tom);
}
}
int height2 = HSV.height();
int width2 = HSV.width();
Mat imgColorida = new Mat(height2, width2, HSV.type());
for (int h = 1; h < height2 - 1; h++) {
for (int w = 1; w < width2 - 1; w++) {
imgColorida.put(h, w, getMedianaColorida(h, w));
}
}
Imgproc.cvtColor(imgColorida, imgColorida, Imgproc.COLOR_HSV2RGB);
Manipulacao m = new Manipulacao();
m.salvarImagem(output1, imgCinza);
m.salvarImagem(output2, imgColorida);
}
示例10: leviBlueFilter
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void leviBlueFilter (Mat input, Mat mask, double threshold){
List<Mat> channels = new ArrayList<>();
Imgproc.cvtColor(input, input, Imgproc.COLOR_RGB2YUV);
Imgproc.GaussianBlur(input,input,new Size(3,3),0);
Core.split(input, channels);
Imgproc.threshold(channels.get(1), mask, threshold, 255, Imgproc.THRESH_BINARY);
for(int i=0;i<channels.size();i++){
channels.get(i).release();
}
}
示例11: getInputDataResNet18
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
private float[] getInputDataResNet18(Bitmap bitmap) {
final int INPUT_SIDE_LENGTH = 224;
Mat imageMat = new Mat();
Utils.bitmapToMat(bitmap, imageMat);
Imgproc.cvtColor(imageMat, imageMat, Imgproc.COLOR_RGBA2BGR);
imageMat = centerCropAndScale(imageMat, INPUT_SIDE_LENGTH);
Core.subtract(imageMat, new Scalar(104, 117, 123), imageMat);
imageMat.convertTo(imageMat, CvType.CV_32FC3);
float[] inputData = new float[imageMat.width() * imageMat.height() * imageMat.channels()];
imageMat.get(0, 0, inputData);
return inputData;
}
示例12: process
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
private void process(Mat f)
{
Mat gen = new Mat();
if (flipActive) Core.flip(f, f, 1);
Imgproc.cvtColor(f, gen, Imgproc.COLOR_BGR2RGB);
if (weirdRenderActive) Imgproc.cvtColor(gen, gen, Imgproc.COLOR_HSV2RGB);
Point mid = new Point(gen.size().width/2, gen.size().height/2);
midPoint = gen.get((int)mid.y, (int)mid.x);
Imgproc.circle(gen, mid, 5, new Scalar(255-(int)(midPoint[0]), 255-(int)(midPoint[1]), 255-(int)(midPoint[2])), 2);
Imgproc.cvtColor(gen, f, Imgproc.COLOR_RGB2BGR);
}
示例13: rgba
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
@Override
public Mat rgba() {
Imgproc.cvtColor(mYuvFrameData, mRgba, Imgproc.COLOR_YUV2RGBA_NV21, 4);
return mRgba;
}
示例14: detectAndDisplay
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
private void detectAndDisplay(final Mat frame, boolean grayIsAlreadySelected) {
MatOfRect faces = new MatOfRect();
Mat grayFrame = new Mat();
if (grayIsAlreadySelected) {
LOGGER.warn("TODO IT :-)");
} else {
// convert the frame in gray scale to ANOTHER frame
Imgproc.cvtColor(frame, grayFrame, Imgproc.COLOR_BGR2GRAY);
}
// equalize the frame histogram to improve the result
Imgproc.equalizeHist(grayFrame, grayFrame);
// compute minimum face size (20% of the frame height, in our case)
if (absoluteAreaSize == 0) {
int height = grayFrame.rows();
if (Math.round(height * 0.2f) > 0) {
absoluteAreaSize = Math.round(height * 0.2f);
}
}
// detect faces
/*
The detectMultiScale function detects objects of different sizes in the input image.
The detected objects are returned as a list of rectangles. The parameters are:
image Matrix of the type CV_8U containing an image where objects are detected.
objects Vector of rectangles where each rectangle contains the detected object.
scaleFactor Parameter specifying how much the image size is reduced at each image scale.
minNeighbors Parameter specifying how many neighbors each candidate rectangle should have to retain it.
flags Parameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade.
minSize Minimum possible object size. Objects smaller than that are ignored.
maxSize Maximum possible object size. Objects larger than that are ignored.
So the result of the detection is going to be in the objects parameter or in our case faces.
*/
CASCADE_CLASSIFIER.detectMultiScale(grayFrame, faces, 1.1, 2,
0 | Objdetect.CASCADE_SCALE_IMAGE, new Size(absoluteAreaSize, absoluteAreaSize), new Size());
/*
each rectangle in faces is a face: draw them!
Let’s put this result in an array of rects and draw them on the frame, by doing so we can display the detected face are.
As you can see we selected the color green with a transparent background: Scalar(0, 255, 0, 255).
.tl() and .br() stand for top-left and bottom-right and they represents the two opposite vertexes.
The last parameter just set the thickness of the rectangle’s border.
*/
final Rect[] facesArray = faces.toArray();
countFaces(facesArray.length);
for (Rect aFacesArray : facesArray)
Imgproc.rectangle(frame, aFacesArray.tl(), aFacesArray.br(), new Scalar(0, 255, 0, 255), 3);
}
示例15: hsvBgrScalar
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public Scalar hsvBgrScalar(double H, double S, double V) {
Mat rgb = new Mat();
Mat hsv = new Mat(1, 1, CvType.CV_8UC3, new Scalar(H, S, V));
Imgproc.cvtColor(hsv, rgb, Imgproc.COLOR_HSV2BGR);
int size = (int) (rgb.total() * rgb.channels());
byte[] data = new byte[size];
rgb.get(0,0,data);
return new Scalar(data[0], data[1], data[2]);
}