15 Ağustos 2017 Salı

OpenCV Imgproc Sınıfı

Canny metodu
Şöyle yaparız.
Mat imgGray =...;
Mat imgCanny = ...;
Imgproc.Canny(imgGray, imgCanny, 50, 150);
cvtColor metodu
Şöyle yaparız.
Mat src = ...;
Mat srcClone = new Mat(); // clone it so it won't affect the original image
Imgproc.cvtColor(src, srcClone, Imgproc.COLOR_BGR2GRAY); // convert the color to gray
dilate metodu
Nesnelerin arasındaki boşlukları doldurur. Şöyle yaparız.
Mat rgbImage = ...
Mat destination = new Mat(rgbImage.rows(), rgbImage.cols(), rgbImage.type());

int dilation_size = 2;

Mat element1 = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, 
  new Size(dilation_size, dilation_size));

Imgproc.dilate(rgbImage, destination, element1);
findContours metoud
Şöyle yaparız.
//find the edges using Canny
Mat edges = new Mat();
Imgproc.Canny(image, edges, 100, 200);

//find the Contour based on Canny result
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat hierarchy = new Mat();
Imgproc.findContours(edges, contours, hierarchy, Imgproc.RETR_EXTERNAL , 
  Imgproc.CHAIN_APPROX_SIMPLE);
GaussianBlur metodu
Şöyle yaparız.
Imgproc.GaussianBlur(mat, dstMat,new Size (15, 15), 0);
Şöyle yaparız.
// add gaussian blur effect to reduce noises
Imgproc.GaussianBlur(image,image, new Size(5,5), 0);
rectangle metodu
Şöyle yaparız.
Mat image = ...;
Rect rect = ...;
Imgproc.rectangle(image, new Point(rect.x, rect.y),
   new Point(rect.x + rect.width, rect.y + rect.height),
   new Scalar(0, 255, 0)
);
threshold metodu
Şöyle yaparız.
Mat image = ...;
Double threshold =  Imgproc.threshold(image, image, 50, 255, Imgproc.THRESH_BINARY);

OpenCV Imgcodecs Sınıfı

Giriş
Şu satırı dahil ederiz.
import org.opencv.core.Mat;
import org.opencv.core.MatOfByte;
import org.opencv.imgcodecs.Imgcodecs;
imencode metodu Şöyle yaparız.
Mat frame = ...;
MatOfByte mem = new MatOfByte(); /// start button 
Imgcodecs.imencode(".bmp", frame, mem);
Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));
imread metodu
Şöyle yaparız.
Mat image = Imgcodecs.imread(Foo.class.getResource("image2.jpg").getPath());  
Şöyle yaparız
String file ="C:/smartphone.jpg";
Mat img = Imgcodecs.imread(file); 
imwrite metodu
Şöyle yaparız.
Mat destination = ...
Imgcodecs.imwrite("C:\\mask.jpg",destination);
Şöyle yaparız.
Mat image = ...;
String filename = "ouput.png";
Imgcodecs.imwrite(filename, image); 

9 Ağustos 2017 Çarşamba

Awt Color Sınıfı

Giriş
Şu satırı dahil ederiz.
import java.awt.Color;
Renk Sabitleri
Hem büyük hem de küçük harf kullanan sabitler var. Şöyle yaparız.
Color color1 = Color.white;
Color color2 = Color.black;
veya
Color.RED
constructor - rgba + hasalpha
Şöyle yaparız.
int argb = 0;
Color c = new Color(argb, true);
darker metodu
Bir sabitin daha koyu rengini alabiliriz.
Örnek ver

getHSBColor metodu
Şöyle yaparız. Hue, saturation, brightness değerleri belirtilir.
Color color = Color.getHSBColor (1, 1, 1);
HSBtoRGB metodu
Şöyle yaparız.
new Color(Color.HSBtoRGB(0, 0, (float)actualValue/maximumValueFromPGMHeader))