image
1. 委派可以將方法當成參數來進行傳遞委派語法:
[public|private|protected] Delegate [void | 回傳資料型態] 委派名稱 ([參數1, 參數2,…]);

me1237guy 發表在 痞客邦 留言(4) 人氣()

image
新增一個抽象類別(範本方法),裡面定義驗算法的骨架TemplateMethod(),包含3個步驟proc1()、proc2()、proc3();這些步驟實作延遲至繼承的子類別去實作,增加了使用上的彈性。
 1: abstract class AbstractClass
 2: {
 3: protected abstract void proc1();
 4: protected abstract void proc2();
 5: protected abstract void proc3();
 6: public void TemplateMethod()
 7: {
 8: proc1();
 9: proc2();
 10: proc3();
 11: MessageBox.Show("TemplateMethod"); 
 12: }
 13: }

me1237guy 發表在 痞客邦 留言(0) 人氣()

「D-Sub插座」的圖片搜尋結果
為了最近新專案的需求,內心經過幾番掙扎,總算下定決心更新的我的電腦配備。今天一早趕緊評估採購桌上電腦,下面三台電腦是在我預算內的候選。最後決定花$39,900買 神隱勇士III 6代i7四核SSD電競獨顯電腦(1) i7 或 i5 其實還好,我並沒有特別偏好(2) 擴充介面: 由於本身做工控,所以PCIe如果有支援PCI(舊)可能更好,因為有些軸卡還是採用PCI‧,PCIe反而不適用。PCIe對於LineScan取像速度很重要,X16算是夠力。(3) SSD硬碟: 對於Visual Studio使用者來說,這個是一定要有的配備,否則光開啟專案就會等個老半天。(4) 獨立顯卡: 之前使用NVidia Cuda運算遇到的狀況是記憶體不夠,我原本舊的顯卡只有1GB,看到目前有到8GB,心動不已。(5) 記憶體: 目前是16GB,最多支援64GB,這個之後會需要補滿。(6) 主機板 GA-B150M-D3H

me1237guy 發表在 痞客邦 留言(0) 人氣()

image
Intel® RealSense™ 攝影機 SR300 下載此檔案︰intel_rs_dcm_sr300先裝上裝置,否則會離開安裝步驟@@C:\Program Files (x86)\Common Files\Intel\RSDCM_SR300
Intel® RealSense™ 攝影機 SR300 的系統需求︰Intel® RealSense™ SDK

me1237guy 發表在 痞客邦 留言(0) 人氣()

image
C:\Program Files (x86)\OMRON\TouchFinder for PC\舊版畫面新版畫面

me1237guy 發表在 痞客邦 留言(0) 人氣()

image
選擇Application WindowApplication Name: AdjContrastDemoLayout: Absolute layout新增兩組JSlider元件新增兩個static變數 alpha、beta完整原始碼
 1: package Basic;
 2:  
 3: import java.awt.EventQueue;
 4: import java.awt.image.BufferedImage;
 5:  
 6: import javax.swing.ImageIcon;
 7: import javax.swing.JFrame;
 8: import javax.swing.JOptionPane;
 9: import javax.swing.JSlider;
 10: import javax.swing.JLabel;
 11: import javax.swing.event.ChangeListener;
 12: import javax.swing.event.ChangeEvent;
 13:  
 14: import org.opencv.core.Core;
 15: import org.opencv.core.Mat;
 16: import org.opencv.imgcodecs.Imgcodecs;
 17: import org.opencv.imgproc.Imgproc;
 18:  
 19: public class AdjContrastDemo {
 20: static{System.loadLibrary(Core.NATIVE_LIBRARY_NAME);}
 21: private JFrame frmContrastAdjustment;
 22: static double alpha = 1;
 23: static double beta = 50;
 24: JSlider slider;
 25: JSlider slider_1;
 26: JLabel lblAlphaVal;
 27: JLabel lblBetaVal;
 28: JLabel lblImage;
 29: static Mat imgSrc;
 30: static Mat imgG = new Mat();
 31: static Mat imgDst = new Mat();
 32: /**
 33:  * Launch the application.
 34:  */
 35: public static void main(String[] args) {
 36: EventQueue.invokeLater(new Runnable() {
 37: public void run() {
 38: try {
 39: //imgSrc = Imgcodecs.imread("C:\\OpenCV\\images\\left01.jpg");
 40: imgSrc = Imgcodecs.imread("C:\\OpenCV\\images\\lena.jpg");
 41: if(imgSrc.empty())
 42: {
 43: JOptionPane.showMessageDialog(null, "無法讀取圖片","警告", 
 44: JOptionPane.WARNING_MESSAGE);
 45: }
 46: if(imgSrc.channels()==3)
 47: imgSrc.copyTo(imgG);
 48: //Imgproc.cvtColor(imgSrc, imgG, Imgproc.COLOR_BGR2GRAY);
 49: else
 50: imgSrc.copyTo(imgG);
 51: //imgDst = new Mat();
 52: AdjContrastDemo window = new AdjContrastDemo();
 53: window.frmContrastAdjustment.setVisible(true);
 54: } catch (Exception e) {
 55: e.printStackTrace();
 56: }
 57: }
 58: });
 59: }
 60:  
 61: /**
 62:  * Create the application.
 63:  */
 64: public AdjContrastDemo() {
 65: initialize();
 66: }
 67:  
 68: /**
 69:  * Initialize the contents of the frame.
 70:  */
 71: private void initialize() {
 72: frmContrastAdjustment = new JFrame();
 73: frmContrastAdjustment.setTitle("Contrast Adjustment");
 74: frmContrastAdjustment.setBounds(100, 100, 725, 692);
 75: frmContrastAdjustment.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 76: frmContrastAdjustment.getContentPane().setLayout(null);
 77: 
 78: slider = new JSlider();
 79: slider.setValue((int)alpha);
 80: slider.addChangeListener(new ChangeListener() {
 81: public void stateChanged(ChangeEvent arg0) {
 82: lblAlphaVal.setText(slider.getValue()+"");
 83: alpha = slider.getValue();
 84: AdjustContrast();
 85: }
 86: });
 87: 
 88: slider.setBounds(125, 40, 370, 19);
 89: frmContrastAdjustment.getContentPane().add(slider);
 90: 
 91: slider_1 = new JSlider();
 92: slider_1.setValue((int)beta);
 93: slider_1.addChangeListener(new ChangeListener() {
 94: public void stateChanged(ChangeEvent arg0) {
 95: lblBetaVal.setText(slider_1.getValue()+"");
 96: beta = slider_1.getValue();
 97: AdjustContrast();
 98: }
 99: });
 100: slider_1.setBounds(125, 90, 370, 19);
 101: frmContrastAdjustment.getContentPane().add(slider_1);
 102: 
 103: JLabel lblAlpha = new JLabel();
 104: lblAlpha.setText("alpha");
 105: lblAlpha.setBounds(55, 29, 71, 36);
 106: frmContrastAdjustment.getContentPane().add(lblAlpha);
 107: 
 108: JLabel lblBeta = new JLabel();
 109: lblBeta.setText("beta");
 110: lblBeta.setBounds(55, 80, 71, 36);
 111: frmContrastAdjustment.getContentPane().add(lblBeta);
 112: 
 113: lblAlphaVal = new JLabel("0");
 114: lblAlphaVal.setBounds(499, 29, 55, 36);
 115: lblAlphaVal.setText(""+alpha);
 116: frmContrastAdjustment.getContentPane().add(lblAlphaVal);
 117: 
 118: lblBetaVal = new JLabel("0");
 119: lblBetaVal.setBounds(499, 80, 55, 36);
 120: lblBetaVal.setText(""+beta);
 121: frmContrastAdjustment.getContentPane().add(lblBetaVal);
 122: 
 123: lblImage = new JLabel("");
 124: lblImage.setBounds(31, 154, 587, 467);
 125: frmContrastAdjustment.getContentPane().add(lblImage);
 126: }
 127: public void AdjustContrast()
 128: {
 129: imgG.convertTo(imgDst, -1, alpha, beta);
 130: BufferedImage bufImg = matToBufferedImage(imgDst);
 131: lblImage.setIcon(new ImageIcon(bufImg));
 132: }
 133: public BufferedImage matToBufferedImage(Mat matrix){
 134: int cols = matrix.cols();
 135: int rows = matrix.rows();
 136: int elemSize = (int)matrix.elemSize();
 137: byte[] data = new byte[cols*rows*elemSize]; 
 138: if(matrix.channels()==3)
 139: Imgproc.cvtColor(matrix, matrix, Imgproc.COLOR_BGR2RGB);
 140: matrix.get(0, 0, data);
 141: BufferedImage bufImg = null;
 142: switch(matrix.channels())
 143: {
 144: case 1:
 145: bufImg = new BufferedImage(cols, rows, BufferedImage.TYPE_BYTE_GRAY);
 146: break;
 147: case 3:
 148: bufImg = new BufferedImage(cols,rows, BufferedImage.TYPE_3BYTE_BGR);
 149: break;
 150: } 
 151: bufImg.getRaster().setDataElements(0, 0, cols, rows, data);
 152: return bufImg; 
 153: }
 154: }

me1237guy 發表在 痞客邦 留言(0) 人氣()

image
OpenCV Mat格式轉 Java BufferedImage格式
 1: public BufferedImage matToBufferedImage(Mat matrix){
 2: int cols = matrix.cols();
 3: int rows = matrix.rows();
 4: int elemSize = (int)matrix.elemSize();
 5: byte[] data = new byte[cols*rows*elemSize]; 
 6: matrix.get(0, 0, data);
 7: BufferedImage bufImg = null;
 8: switch(matrix.channels())
 9: {
 10: case 1:
 11: bufImg = new BufferedImage(cols, rows, BufferedImage.TYPE_BYTE_GRAY);
 12: break;
 13: case 3:
 14: bufImg = new BufferedImage(cols,rows, BufferedImage.TYPE_3BYTE_BGR);
 15: break;
 16: } 
 17: bufImg.getRaster().setDataElements(0, 0, cols, rows, data);
 18: return bufImg; 
 19: }

me1237guy 發表在 痞客邦 留言(0) 人氣()

image
輸入library名稱點選OpenCV3.1,按下Add External JARs。事先解壓縮OpenCV3.1, 選擇build資料夾下java選擇opencv-310Native library location 滑鼠雙擊或 Edit 進入編輯我的Eclipse安裝x86,所以選x86。原本以為是電腦的作業系統為主,我的電腦是x64,但安裝x64版本到後面步驟就掛掉…設定好如下所示:來寫一個OpenCV範例選取User Library,按下Next勾選OpenCV3.1,按下Finish。

me1237guy 發表在 痞客邦 留言(0) 人氣()

image_thumb1
接續上一個project新增JSlider至frame加入slider拖拉事件Run( 或按下CTRL+F11)

me1237guy 發表在 痞客邦 留言(0) 人氣()

image
https://www.java.com/zh_TW/download/-------------------------Eclipse安裝我的電腦是64位元,但是下載Windows 64-bit卻無法開啟IDE,參考[2]依然無法解決,後來索性下載Windows 32-bit竟然順利解決! 懷疑因為我的jre安裝32-bit的關係@@C:\Users\me1237guy\workspace新增Java Package新增Java Class
 1: package ex1;
 2:  
 3: public class ex1_helloworld {
 4:  
 5: public static void main(String[] args) {
 6: // TODO Auto-generated method stub
 7: System.out.println("Hello World!");
 8: }
 9:  
 10: }

me1237guy 發表在 痞客邦 留言(0) 人氣()

image
contour line: blue colorconvex hull line: red colorstep 1: point 1(light blue) represents a start point, point 2(green) is end point, and point 3 (red) is defect size which is defined as the distance between light blue color line and red cicular point. step 2:step 3:step 4:---------------------------------Now I am going to show you three different sizes of star logos, which are proportional to their defect sizes. figure 0 is a large size logo, and its defect size is about 6984.

me1237guy 發表在 痞客邦 留言(0) 人氣()

image

繼續上一篇 OpenCV3.1 搜尋輪廓與遮罩應用

現在要計算輪廓周長、面積和重心,並且用一多邊形曲線近似該輪廓。

 1:  
 2: for (int i = 0; i < contours.size(); i++) {
 3: cout << "contour # " << i << endl;
 4: imgMask = Mat::zeros(imgSrc.size(), CV_8UC1);
 5: drawContours(imgMask, contours, i, Scalar(255), -1);
 6: Mat imgROI;
 7: imgSrc.copyTo(imgROI, imgMask);
 8: string name = std::to_string(i);
 9: //imshow(name, imgROI);
 10: cout << "mean color (BGR) = " << mean(imgSrc, imgMask) << endl;
 11: Moments m = moments(contours[i]);
 12: cout << "area = " << m.m00 <<endl;
 13: double contArea = contourArea(contours[i]);
 14: cout << "contour area = " << contArea << endl;
 15: double cx = m.m10 / m.m00;
 16: double cy = m.m01 / m.m00;
 17: line(imgROI, Point(cx, cy), Point(cx, cy), Scalar(255, 0, 0), 5, 8);
 18: char label[50];
 19: sprintf_s(label, "(%.0f,%.0f)", cx, cy);
 20: int offset = 100;
 21: putText(imgROI, label, Point(cx-offset, cy), FONT_HERSHEY_COMPLEX, 1, Scalar(0, 0, 255), 1, 8);
 22: double perimeter = arcLength(contours[i], true);
 23: cout << "perimeter = " << perimeter << endl;
 24: vector<Point> polyCurves;
 25: double epsilon = 0.01;
 26: approxPolyDP(contours[i], polyCurves, epsilon*arcLength(contours[i], true), true);
 27: 
 28: cout << "polygonal curves = " << polyCurves.size() << endl;
 29: for (int j = 0; j < polyCurves.size()-1; j++) 
 30: {
 31: Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
 32: line(imgROI, polyCurves[j], polyCurves[j + 1], color, 3, 8);
 33: }
 34:  
 35: line(imgROI, polyCurves[0], polyCurves[polyCurves.size()-1], Scalar(0, 0,255), 3, 8);
 36: 
 37: imshow(name, imgROI);
 38: cout << "------------------------------" << endl;
 39: }
多邊形曲線近似 epsilon = 0.01多邊形曲線近似 epsilon = 0.02--------------------------------------輪廓極值(minX, maxX, minY, maxY)
 1:  
 2: bool sortByXAscend(Point a, Point b) { return (a.x<b.x); }
 3: bool sortByXDescend(Point a, Point b) { return (a.x>b.x); }
 4: bool sortByYAscend(Point a, Point b) { return (a.y<b.y); }
 5: bool sortByYDescend(Point a, Point b) { return (a.y>b.y); }

me1237guy 發表在 痞客邦 留言(0) 人氣()

Blog Stats
⚠️

成人內容提醒

本部落格內容僅限年滿十八歲者瀏覽。
若您未滿十八歲,請立即離開。

已滿十八歲者,亦請勿將內容提供給未成年人士。