이하 코드는 주피터 노트북에서 실행했다.

 

 

1
2
3
4
5
6
7
8
import tensorflow as tf
hello = tf.constant("Hello, Tensorflow!")
sess = tf.Session()
print(sess.run(hello))
= tf.constant(10)
= tf.constant(20)
print(sess.run(a + b))
sess.close()
cs

실행 결과 : 

b'Hello, Tensorflow!'

30

hello = tf.constant("Hello, Tensorflow!")

hello라는 변수에 str을 저장한 듯 하다.

sess = tf.Session()

sess라는 변수에 Session()함수를 저장한 듯 하다.

이후는 print를 이용해 출력을 하는 과정인데, run()이라는 함수를 이용한다.

 

코드:

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
#include <iostream>
#include <opencv2/opencv.hpp>
 
using namespace std;
using namespace cv;
 
int main() {
    VideoCapture cap; //카메라 또는 비디오 파일로 부터 프레임을 읽는데 필요한 정보
    cap.open("bike.avi");
 
    if (!cap.isOpened()) {
        return -1;
    }
    namedWindow("Video");
    Mat frame;
    int fps = (int)cap.get(CAP_PROP_FPS); //초당 프레임 수
    while (1) {
        if (!cap.read(frame)) //파일 끝에 도달하면 false 반환
            break;
        imshow("Video", frame);
        if (waitKey(1000 / fps) >= 0break//키보드 입력으로 재생을 멈추고자 할 때
    }
    cap.release(); return 0;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs
 
 
 

실행결과:

 

설명:

VideoCapture cap;

    cap.open("bike.avi"); 

if (!cap.isOpened()) {

        return -1;

    }

avi파일을 가져와서 open.

 

   namedWindow("Video");

윈도우창 이름 설정

 

    Mat frame;

    int fps = (int)cap.get(CAP_PROP_FPS); //초당 프레임 수

    while (1) {

        if (!cap.read(frame)) //파일 끝에 도달하면 false 반환

            break;

        imshow("Video", frame);

        if (waitKey(1000 / fps) >= 0break//키보드 입력으로 재생을 멈추고자 할 때

    }

    cap.release(); return 0;

비디오 보여주는 코드

1000을 초당 프레임 수로 나누면 기본 속도로 재생이 되고 1000에서 줄이거나 늘려서 재생속도를 조절할 수 있다.

 

 

 

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

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

코드:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <opencv2/opencv.hpp>
 
using namespace std;
using namespace cv;
 
int main() {
    Mat img(300500, CV_8UC1, Scalar(255));
    Point2f center(250150), pts[4];
    Size2f size(300100);
    RotatedRect rot_Rect(center, size, 50);
    Rect bound_Rect = rot_Rect.boundingRect();
    rectangle(img, bound_Rect, Scalar(0), 1);
    circle(img, rot_Rect.center, 1, Scalar(0), 2);
    rot_Rect.points(pts);
    for (int i = 0; i < 4; i++) {
        circle(img, pts[i], 4, Scalar(0), 2);
        line(img, pts[i], pts[(i + 1) % 4], Scalar(0), 1);
    }
    imshow("사각형", img);
    waitKey(0);
}
 
 
cs

 

실행결과:

 

 

설명:

Mat img(300500, CV_8UC1, Scalar(255));

세로 300, 가로 500 화면, 흑백, Scalar(255) = 흰색

 

Point2f center(250150), pts[4];

직사각형의 가운데 점 250, 150, 그 중심으로 점 네개 정의.

 

Size2f size(300100);

직사각형의 크기

 

RotatedRect rot_Rect(center, size20);

회전된 직사각형 출력, 중심점은 위에 정의한 center, 크기는 size, 회전 각도는 20도

 Rect bound_Rect = rot_Rect.boundingRect();

위의 직사각형을 감싸는 사각형 정의

 

rectangle(img, bound_Rect, Scalar(0), 1);

img는 왜쓰는지 모르겠다. 위에 정의한 bound_Rect, 사각형테두리 색은 Scalar(0) = 검은색, 1은 굵기

 

circle(img, rot_Rect.center, 1, Scalar(0), 2);

rot_Rect.center에 원, 1은 원 크기, 사각형테두리 색은 Scalar(0) = 검은색, 2는 굵기

 

    for (int i = 0; i < 4; i++) {

        circle(img, pts[i], 4, Scalar(0), 2);

        line(img, pts[i], pts[(i + 1) % 4], Scalar(0), 1);

    }

RotadedRect각 꼭지점에 원 출력

RotadedRect각 꼭지점 연결 = 사각형 모양 완성

 

  imshow("사각형", img);

그린거(img) 출력.

 

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

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

+ Recent posts