1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package source;
 
import java.awt.AWTException;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.io.File;
import java.io.IOException;
 
import javax.imageio.ImageIO;
/**
 13  * 화면 위에 지정한 그림 찾기
 14  * @author Jeby Sun
 15  * @date 2014-09-13
 16  * @website http://www.jebysun.com
  */
 public class ImageFindDemo {
     
     BufferedImage screenShotImage;    //화면 캡처
     BufferedImage keyImage;           //검색 대상 그림
     Image imagekey;
 
     int scrShotImgWidth;              //스크린샷 너비
     int scrShotImgHeight;             //스크린샷 높이
   
      int keyImgWidth;                  //검색 대상 이미지 너비
      int keyImgHeight;                 //목표 이미지 높이 찾기
      
      int[][] screenShotImageRGBData;   //화면 캡처 RGB 데이터
      int[][] keyImageRGBData;          //검색 대상 그림 RGB 데이터
      
      int[][][] findImgData;            //검색 결과 목표 아이콘 화면 캡처 위의 좌표 데이터 
      
      
      public ImageFindDemo()  {
          screenShotImage = this.getFullScreenShot();
          //imagekey = Toolkit.getDefaultToolkit().getImage(getClass().getClassLoader().getResource("DPIcon.jpg"));
         
          
          ImageObserver obserb = new ImageObserver() {
            
            @Override
            public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
                // TODO Auto-generated method stub
                return false;
            }
        };
          try {
            keyImage = ImageIO.read(new File("Img/DPIcon.jpg"));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
          screenShotImageRGBData = this.getImageGRB(screenShotImage);
          keyImageRGBData = this.getImageGRB(keyImage);
          scrShotImgWidth = screenShotImage.getWidth();
          scrShotImgHeight = screenShotImage.getHeight();
          keyImgWidth = keyImage.getWidth();
          keyImgHeight = keyImage.getHeight();
          
          //찾기 시작했다
          this.findImage();
          
      }
      
      /**
       * 전체 화면 캡처
       * @return 복귀 BufferedImage
       */
      public BufferedImage getFullScreenShot() {
          BufferedImage bfImage = null;
          int width = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();
          int height = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();
          try {
              Robot robot = new Robot();
              bfImage = robot.createScreenCapture(new Rectangle(00, width, height));
          } catch (AWTException e) {
              e.printStackTrace();
          }
          return bfImage;
     }
      
      /**
       * 로컬 파일 읽기 목표 이미지
       * @param keyImagePath - 그림 절대 경로
       * @return 로컬 그림 BufferedImage 대상
       */
      public BufferedImage getBfImageFromPath(String keyImagePath) {
          BufferedImage bfImage = null;
          try {
              bfImage = ImageIO.read(new File(keyImagePath));
          } catch (IOException e) {
              e.printStackTrace();
          }
          return bfImage;
      }
      
      /**
       * 근거 BufferedImage 그림 RGB 배열 가져오기
       * @param bfImage
       * @return
       */
      public int[][] getImageGRB(BufferedImage bfImage) {
          int width = bfImage.getWidth();
          int height = bfImage.getHeight();
          int[][] result = new int[height][width];
          for (int h = 0; h <height; h++) {
              for (int w = 0; w <width; w++) {
                  //사용 getRGB (w, h) 가져오는 중 이 색을 값, ARGB 아닌 실제 프로그램 중 사용, RGB. 그래서 다변화가 필요하다 ARGB 전환의 만든 RGB, 즉 bufImg.getRGB(w, h) & 0xFFFFFF. 
                  result[h][w] = bfImage.getRGB(w, h) & 0xFFFFFF;
              }
         }
          return result;
      }
      
     
     /**
      * 그림 찾기
      */
     public void findImage() {
         findImgData = new int[keyImgHeight][keyImgWidth][2];
         //화면 캡처 픽셀 좀 데이터 사이를 옮겨다니기
         for(int y=0; y<scrShotImgHeight-keyImgHeight; y++) {
             for(int x=0; x<scrShotImgWidth-keyImgWidth; x++) {
                 //대상 그림 크기 근거하여 얻은 목표 도 사각 맵 화면 위에 네 시 까지, 
                 //판단 스크린샷 위에 대응 네 개 좀 와 그림 B 네 개 픽셀 값을 같은 있는지 좀, 
                 //만약 같은 스며들게 화면 위에 맵 범위 내의 모든 좀 목표 도 모든 좀 비교해 보다. 
                 if((keyImageRGBData[0][0]^screenShotImageRGBData[y][x])==0
                         && (keyImageRGBData[0][keyImgWidth-1]^screenShotImageRGBData[y][x+keyImgWidth-1])==0
                         && (keyImageRGBData[keyImgHeight-1][keyImgWidth-1]^screenShotImageRGBData[y+keyImgHeight-1][x+keyImgWidth-1])==0
                         && (keyImageRGBData[keyImgHeight-1][0]^screenShotImageRGBData[y+keyImgHeight-1][x])==0) {
                     
                     boolean isFinded = isMatchAll(y, x);
                     //만약 비교적 결국 완전히 같지 않으면 설명이 그림 찾을 때까지 충전 중 위치 까지 좌표 데이터 검색 결과 배열. 
                     if(isFinded) {
                         for(int h=0; h<keyImgHeight; h++) {
                             for(int w=0; w<keyImgWidth; w++) {
                                 findImgData[h][w][0= y+h; 
                                 findImgData[h][w][1= x+w;
                             }
                         }
                         return;
                     }
                 }
             }
         }
     }
     
     /**
      * 판단 화면 위에 목표 도 맵 범위 내의 모든 것이 다 좀, 작은 그림 좀 일일이 대응. 
      * @param y - 목표 그림 왼쪽 위 픽셀 좀 하고 일치하는 화면 y 좌표
      * @param x - 목표 그림 왼쪽 위 픽셀 좀 하고 일치하는 화면 x 좌표
      * @return 
      */
     public boolean isMatchAll(int y, int x) {
         int biggerY = 0;
         int biggerX = 0;
         int xor = 0;
         for(int smallerY=0; smallerY<keyImgHeight; smallerY++) {
             biggerY = y+smallerY;
             for(int smallerX=0; smallerX<keyImgWidth; smallerX++) {
                 biggerX = x+smallerX;
                 if(biggerY>=scrShotImgHeight || biggerX>=scrShotImgWidth) {
                     return false;
                 }
                 xor = keyImageRGBData[smallerY][smallerX]^screenShotImageRGBData[biggerY][biggerX];
                 if(xor!=0) {
                     return false;
                 }
             }
             biggerX = x;
         }
         return true;
     }
     
     /**
      * 출력 검색 온 좌표 데이터
      */
     private void printFindData() {
         for(int y=0; y<keyImgHeight; y++) {
             for(int x=0; x<keyImgWidth; x++) {
                 System.out.print("("+this.findImgData[y][x][0]+", "+this.findImgData[y][x][1]+")");
             }
             System.out.println();
         }
     }
 
     
     public static void main(String[] args) {
         ImageFindDemo demo = new ImageFindDemo();
         demo.printFindData();
     }
 
}
 
cs


자료는 ProgrammerKR 구글 서치중 찾았다.


바탕화면 캡처 후 원하는 이미지와 좌표에 맞춰 RGB 대조 형식으로 진행.


출력은 전체 좌표를 출력함.

'javaSkills' 카테고리의 다른 글

Thread 의 sleep과 interrupt  (0) 2016.06.09
jar파일에서 이미지 로딩이 안되요!  (0) 2016.01.14
JAVA 실시간 그래프  (0) 2015.11.18
Hex String -> byte array , byte array -> hex String  (0) 2015.11.05
자바 int to hex  (0) 2015.11.05

여지껏 자바, C와 씨름하다가 이제 하드웨어와 접목하는 펌웨어 부분으로 넘어가게 되었다. 


틈틈히 책으로만 복습하던 마이크로 프로세서 공부였는데 드디어 본격적으로 시작한다...



제품의 디버깅 속도와 writing 속도는 나쁘지 않은것 같다. 세부적인 옵션은 모르겠으나


글이 그렇게 많지 않은것을 봐서는 안되는 옵션도 많은것 같다.



차후 마이크로프로세스에 대해 포스트 하면서 Atmel - ICE에 관해서도 포스트를 하겠습니다~.

여지껏 골치를 썩혀왔던 문제이다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
try {
    try
    {
        while(!Thread.curruntThread.isInturrupt)
        {
        ..... 
        }    
    catch(InterruptedException e)
    {
 
    }
}
 
finally
{
 
}

cs


이 코드와 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
try {
    try
    {
        while(!Thread.curruntThread.isInturrupt)
        {
        ..... 
        }    
    }
}
catch(InterruptedException e)
{
 
}    
finally
{
 
}
cs


이 코드의 차이가  어마어마 하다 . 


윗 코드는 Thread가 sleep에 들어갈 경우 "sleep 중에 Interrup 했다!" 라는 Error를 띄우지만 


아래 코드는 "Thread를 오류가 나도 죽일게! "라는 코드이다.



많은 블로그에서 이 부분에 관해 포스트를 하셧지만 


결정적인 실수는 Catch의 위치에 따라 멈추냐 안멈추냐 차이이다. (이상동작도 발생한다)



참고 : http://javafreak.tistory.com/210 

해결이 안됬다가 해결했다 . 

방법은 

1
getClass().getClassLoader().getResource("이미지 이름")
cs


클래스 로더에서 리소스를 호출하는 것이다.


물론 이것만 하면 Eclipse 개발환경에서는 Null 포인터가 바로 뜬다. 


그래서 해줘야 할것은 프로젝트에서 properties에서

이런식으로 Add Folder를 선택후 본인이 필요한 이미지가 있는 폴더를 프로젝트 내에서 컨택하면 된다.

그러면 Null Pointer도 문제없이 컴파일이 된다.



1
2
3
Byte[] bytes = (Byte[]) arrayList.toArray(); //  ArrayList -> Byte[]
 
arrayList = new ArrayList(Arrays.asList(bytes )); // Byte[] -> ArrayList
cs


(만약 프리미티브 byte[]로 전환하고자 하신다면, Bytes[X].byteValue() 를 X값을 루프를 돌면서 복사해주면됩니다.)


출처 : http://mungi.kr/177



1
2
3
4
5
6
7
8
9
10
11
12
13
14
        int Decint = Integer.parseInt(Dec); 
        byte [] bytes = {0x00,0x00};
        String hexto04="";
        String hex = Integer.toHexString(Decint);
        if(Decint<0)
        {
            hexto04 = hex.substring(hex.length()-4);
            bytes = new java.math.BigInteger(hexto04,16).toByteArray();
        }
        else if(Decint>0)
        {
            bytes = new java.math.BigInteger(hex,16).toByteArray();
        }
        return bytes ;
cs

출처 : http://ecogeo.tistory.com/129


위의 hexString to byte 같은 경우 음수가 들어오면 변환은 내가 대충 짜본것이다.



추가 

wrapper 가 아닌 primetive byte[] 전환 

1
2
3
4
byte [] bytes =  new byte[sendbyte.size()];
            for (int i = ; i<sendbyte.size();i++){
                bytes[i]= sendbyte.get(i);
            }
cs


다음 글은 이상훈 (http://blog.beany.co.kr/archives/3433#comment-10162)님의 글입니다 ... 정말 감사합니다 큰도움이 되었습니다.


Git Server 에서 프로젝트 가져오기

프로젝트 Import

Git Server 에서 프로젝트를 가져오기 위하여 상단의 메뉴에서 [File -> Import …] (1) 을 클릭합니다.
eclipse_git_import_project_1
Import 팝업창이 나타나면 [Git -> Projects from Git] (1) 항목을 선택한 후 [Next >] 버튼을 클릭합니다.
eclipse_git_import_project_2
Git Server 에서 가져오기 위하여 URI (1) 항목을 선택한 후 [Next >] 버튼을 클릭합니다.
eclipse_git_import_project_3
URI (1) 에 Git Server 의 프로젝트 URL 을 입력한 후 Authentication (2) 항목에 Git Server 계정을 입력한 후 [Next >] 버튼을 클릭합니다.
eclipse_git_import_project_4
[Next >] 버튼을 클릭합니다.
eclipse_git_import_project_5
Git 로컬 저장소 디렉토리를 확인한 후 [Next >] 버튼을 클릭합니다.
eclipse_git_import_project_6
Import existing projects (1) 항목을 선택한 후 [Next >] 버튼을 클릭합니다.
eclipse_git_import_project_7
생성할 프로젝트를 확인한 후 [Finish] 버튼을 클릭하면 프로젝트를 Git Server 로 부터 다운로드 받습니다.
eclipse_git_import_project_8
정상적으로 프로젝트를 가져오면 Package Explorer (1) 항목에 프로젝트가 생성되며, Git 로컬 저장소 (2) 도 생성되게 됩니다.
eclipse_git_import_project_9

다음 글은 http://blog.beany.co.kr/archives/3407#comment-10161 이상훈(imfjbh@gmail.com) 님의 글입니다. 

정말 큰 도움이 됬습니다 ㅠㅠ 


프로젝트 공유

Git 으로 공유할 프로젝트를 선택한 후 마우스 오른쪽 버튼을 클릭한 후 [Team -> Share Project … ] (1) 을 선택합니다.
eclipse_git_share_project_1
공유할 저장소를 Git (1) 으로 선택한 후 [Next >] 버튼을 클릭합니다.
eclipse_git_share_project_2
프로젝트 공유를 위한 Git 로컬 저장소를 생성합니다. [Create …] (1) 버튼을 클릭합니다.
eclipse_git_share_project_3
[Browse …] (1) 버튼을 클릭하여 로컬 저장소의 폴더 위치를 선택합니다. Name (2) 은 Git 로컬 저장소의 이름을 입력하시면 됩니다.
eclipse_git_share_project_4
Git 로컬 저장소 디렉토리가 정상적으로 설정되었는지 Repository (1) 항목과 Target Location (2) 항목을 확인한 후 [Finish] 버튼을 클릭합니다.
eclipse_git_share_project_5
프로젝트에서 마우스 오른쪽 버튼을 클릭한 후 [Team -> Add to Index] (1) 메뉴를 클릭합니다.
eclipse_git_share_project_6
Add to Index 명령을 실행하고 나서는 프로젝트의 하위 폴더 및 파일에 ‘?’ 표시에서 ‘*’ 표시로 변경됩니다.
eclipse_git_share_project_7
프로젝트에서 마우스 오른쪽 버튼을 클릭한 후 [Team -> Commit …] (1) 항목을 클릭합니다.
eclipse_git_share_project_8
Commit message 를 입력한 후 [Commit] 버튼을 클릭하면 프로젝트가 정상적으로 Git 로컬 저장소에 반영되게 됩니다.
eclipse_git_share_project_9

프로젝트 Push

Git Server 에 프로젝트를 공유하기 위해서는 프로젝트에서 마우스 오른쪽 버튼을 클릭한 후 [Team > Push …] (1) 항목을 클릭합니다.
eclipse_git_share_project_push_1
URI (1) 항목에 Git Server 의 저장소 주소를 입력한 후 Authentication (2) 항목에는 발급받은 Git Server 의 계정을 입력하신후에 [Next >] 버튼을 클릭합니다.
eclipse_git_share_project_push_2
Source ref (1) 항목을 ‘refs/heads/master‘ 로 선택하시면 Destination ref (2) 항목도 자동으로 ‘refs/heads/master’ 로 만들어 집니다. [Add Spec] (3) 버튼을 클릭합니다.
eclipse_git_share_project_push_3
[Add Spec] 버튼을 클릭한 후에는 Specifications for push (1) 영역에 정상적으로 등록이 되었는지 확인한 후 [Next >] 버튼 또는 [Finish] 버튼을 클릭하여 Git Server 로 프로젝트 공유 설정을 마칠수 있습니다.
eclipse_git_share_project_push_4
Git Server 에 Push 관련 메시지를 확인한 후 [Finish] 버튼을 클릭합니다.
eclipse_git_share_project_push_5
정상적으로 Git Server 로 Push 가 수행되면 아래와 같은 메시지 창이 나타나며 [OK] 버튼을 클릭하여 설정을 종료합니다.
eclipse_git_share_project_push_6

처음부터 진행하는 법은 

http://www.tutorialbook.co.kr/entry/Synology-NAS-%EB%A5%BC-%EC%9D%B4%EC%9A%A9%ED%95%98%EC%97%AC-git-%EC%84%9C%EB%B2%84-%EA%B5%AC%EC%84%B1%ED%95%98%EA%B8%B0

여기를 따라서 한다. 서버 SSH 에서 URL 을 추가해서 하도록 한다.


clone 만들어서 서버 TEST 후 (중요 : synology Git 프로그램에서 사용자를 허용해야 한다)

http://itmir.tistory.com/461

위의 링크에서 두번째 방법으로 URL 추가한다.

http://blog.naver.com/platinum4/220008130101 

'실무' 카테고리의 다른 글

사용중인 COM port 초기화  (0) 2015.12.04

+ Recent posts