코드:

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
from tkinter import*
 
#function which actions when the button is pushed
def convert():
    f = float(ent.get())
    tmp = float(5 * (f - 32/ 9)
    #print(tmp)
    lbl_2.configure(text = str(tmp))
    return
 
root = Tk()
root.title("temperature program")
root.geometry("230x120")
 
lbl_1 = Label(root, text = "Fahrenheit")
ent = Entry(root)
lbl_2 = Label(root, text = "Celsius")
btn = Button(root, text = "change to Celsius", command = convert)
 
lbl_1.place(x = 10, y = 20)
ent.place(x = 50, y = 20)
btn.place(x = 50, y = 40)
lbl_2.place(x = 50, y = 80)
 
root.mainloop()
 
cs

 

실행결과:

 

설명:

root = Tk()

위도우를 만들어서 root변수에 저장.

 

root.title("temperature program")

만든 윈도우에 이름을 지정.

 

root.geometry("230x120")

윈도우 창의 크기

 

lbl_1 = Label(root, text = "Fahrenheit")

Lable()함수를 이용해서 라벨 생성

 

ent = Entry(root)

Entry()함수를 이용해서 입력창 생성

 

btn = Button(root, text = "change to Celsius", command = convert)

Button()함수를 이용해서 버튼 생성, 함수는 command로 호출한다.

 

def convert():

    f = float(ent.get())

    tmp = float(5 * (f - 32/ 9)

    #print(tmp)

    lbl_2.configure(text = str(tmp))

    return

함수 생성부분,  lbl_2.configure(text = str(tmp)) configure()함수를 이용해서 두번째 라벨의 내용을 결과값으로 바꾸는 함수다.

 

lbl_1.place(x = 10, y = 20)

place()함수를 이용해서 해당 좌표에 라벨을 붙이는 코드.

 

 

 

코드:

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
package CIrcle;
 
class Circle{
    int radius;
    public Circle(int radius) {
        this.radius = radius;
    }
    public double getArea() {
        return 3.14*radius*radius;
    }
}
public class Circle_Array {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Circle[] c;
        c = new Circle[5];
 
        for(int i = 0; i < c.length; i++) {
            c[i] = new Circle(i);
        }
        for(int i = 0; i < c.length; i++) {
            System.out.println((int)c[i].getArea() + " ");
        }
    }
 
}
 
cs

 

실행결과:

 

설명:

 Circle[] c;

 c = new Circle[5];

변수 c에 5개의 Circle 객체를 저장했다.

위쪽에 만든 것이 Circle의 클래스이고 메인 함수에서 Circle객체를 만드는 코드이다.

'Java' 카테고리의 다른 글

Java, String(2)  (0) 2019.10.04
Java, String(1)  (0) 2019.10.04
Java, Interger.parseInt(), 예외처리  (0) 2019.09.25
Java, Array  (0) 2019.09.25
Java, for-while, continue, Scanner  (0) 2019.09.25

코드:

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
#include <iostream>
#include <opencv2/opencv.hpp>
 
using namespace std
using namespace cv;
void detectHScolor(const cv::Mat&  image, double minHue,
    double maxHue, double minSat, double  maxSat, Mat&  mask);
 
int main() {
    Mat image = imread("girl.jpg");
    Mat mask;
    detectHScolor(image, 1601025166, mask);
    Mat detected(image.size(), CV_8UC3, Scalar(000));//하얗게 주려면 255,255,255
    image.copyTo(detected, mask);
    imshow("Girl", image);
    imshow("Detected", detected);
    waitKey(0);
}
 
 
 
void detectHScolor(const Mat&  image, double minHue, double maxHue, double minSat, double  maxSat, Mat&  mask) {
    //detect by hue(minHue~maxHue), saturate(minSat~maxSat) 
    Mat hsv;
    cvtColor(image, hsv, COLOR_BGR2HSV); //conver BGR to HSV
 
    vector<Mat>  channels;
    split(hsv, channels);    //split channels
    double minVal = 0, maxVal = 0;
    minMaxLoc(channels[0], &minVal, &maxVal, 00);
    cout << "min= " << minVal << " max= " << maxVal << endl//min=0, max=179
    Mat  mask1;   //maxHue 이하는 255, 이상은 0
    threshold(channels[0], mask1, maxHue, 255, THRESH_BINARY_INV);
    Mat  mask2; //minHue 이하는 0, 이상은 255   
    threshold(channels[0], mask2, minHue, 255, THRESH_BINARY);
    Mat hueMask;
    if (minHue < maxHue)  hueMask = mask1 & mask2;
    else hueMask = mask1 | mask2;
    //색상 범위가 0을 포함할 때 즉 160 ~ 10 사이 색상
 
    //채도 마스크
    threshold(channels[1], mask1, maxSat, 255, THRESH_BINARY_INV);
    threshold(channels[1], mask2, minSat, 255, THRESH_BINARY);
 
    Mat satMask;
    satMask = mask1 & mask2;
    //0와 255로 구성된 mask: 255인 곳이 얼굴 영역: 이영역만 원본 영상에서 copy
    mask = hueMask & satMask;
}
 
cs
실행결과:

 

설명:

 

 

 

 

 

'C,C++ > Opencv, c++' 카테고리의 다른 글

Opencv, c++, cvtColor(), split(), merge()  (0) 2019.10.04
Opencv, c++, imshow, imwrite  (0) 2019.10.04
Opencv, c++, video 출력  (0) 2019.09.22
Opencv, c++, Rectangle 출력  (0) 2019.09.22

+ Recent posts