for Robot Artificial Inteligence

2. Cartoon Effect

|

Create a Cartoon Image

  • Stylization aims to produce digital imagery with a wide variety of effects not focused on photorealism. Stylization can abstract regions of low contrast while preserving, or enhancing, high-contrast features.
  • Parameters
    • src Input 8-bit 3-channel image.
    • dst Output image with the same size and type as src.
    • sigma_s Range between 0 to 200.
    • sigma_r Range between 0 to 1.
  • Note
    • sigma_s controls how much the image is smoothed - the larger its value, the more smoothed the image gets, but it’s also slower to compute.
    • sigma_r is important if you want to preserve edges while smoothing the image. Small sigma_r results in only very similar colors to be averaged (i.e. smoothed), while colors that differ much will stay intact.
import cv2 #opencv library
import matplotlib.pyplot as plt #create a matplotlib

color_image = cv2.imread("trudeau.jpg") # reading image file by using cv2.imread("trudeau.jpg")

cartoon_image = cv2.stylization(color_image, sigma_s=100, sigma_r=0.1)
#cartoon_image, cartoon_image2  = cv2.pencilSketch(color_image, sigma_s=60, sigma_r=0.1)

cv2.imshow('cartoon', cartoon_image)
cv2.waitKey() #wating any key
cv2.destroyAllWindows()

Example

import matplotlib.image as mpimg #had to perform many someting handy for us. image read function.
import matplotlib.pyplot as plt
import numpy as np # numerical analysis
import cv2
image_color = mpimg.imread("trudeau.jpg")


plt.imshow(image_color)
image_gray = cv2.cvtColor(image_color, cv2.COLOR_BGR2GRAY)
# our picture and color funtion.
plt.imshow(image_gray, cmap = 'gray') # 'gray' we have to give them color
image_gray.shape
# (569,800)
image_gray #each of pixel presenting in the color
# (569,800,3)
array([[ 19,  21,  22, ..., 159, 160, 161],
       [ 18,  19,  21, ..., 159, 161, 162],
       [ 17,  19,  20, ..., 160, 161, 162],
       ...,
       [139, 140, 143, ..., 132, 132, 131],
       [139, 140, 143, ..., 131, 130, 129],
       [136, 140, 144, ..., 126, 126, 126]], dtype=uint8)
# Save the image in greyscale
cv2.imwrite("image_grayscale.jpg", image_gray)
# save the image. # specifiy the name of image when we save
# true means that actually save it
color_image = cv2.imread("trudeau.jpg")

# cartoon_image = cv2.stylization(color_image, sigma_s=200, sigma_r=0.3)
cartoon_image, cartoon_image2  = cv2.pencilSketch(color_image, sigma_s=60, sigma_r=0.1)
# pencilsketch has two return value. cartoon_image is not color, cartoon_image2 is the colorful by pencil
cv2.imshow('cartoon', cartoon_image2)
cv2.waitKey()
cv2.destroyAllWindows()

Comment  Read more

2.Logical-Operators

|

Example 1

#include <iostream>

using namespace std;

main()
{
    /*
        AND conjunction &&

        7 > 5 && 5 != 10 //conjunction is true ONLY if both expressions are true

        expr1 expr2 result
          0     0     0
          0     1     0
          1     0     0
          1     1     1

        OR disjunction || (alternative)

        disjunction is false ONLY when both expressions are false

        expr1 expr2 result
          0     0     0
          0     1     1
          1     0     1
          1     1     1

        ! (exclemation mark) - NOT

        ! (0) the result will be 1
        ! (1) the result will be 0
    */

    cout << !(5 > 7 || 5 != 10) << endl;


}

Example 2

#include <iostream>

using namespace std;

main() {

    int minValue, maxValue, elementToCheck;
    bool isContained;

    cout << "Please input the minimum value: ";
    cin >> minValue;
    cout << "Please input the maximum value: ";
    cin >> maxValue;
    cout << "Please input the number to check: ";
    cin >> elementToCheck;

    isContained = (minValue <= elementToCheck) && (elementToCheck <= maxValue);
    cout << "Is the number " << elementToCheck << " contained in the interval from " << minValue << " to " << maxValue << " ? " << isContained;

}

Example 3

#include <iostream>

using namespace std;

main() {

    int minValue, maxValue, elementToCheck;
    bool isGreaterThanMinValue, isLowerThanMaxValue;

    cout << "Please input the minimum value: ";
    cin >> minValue;
    cout << "Please input the maximum value: ";
    cin >> maxValue;
    cout << "Please input the number to check: ";
    cin >> elementToCheck;

    isGreaterThanMinValue = (minValue <= elementToCheck);
    isLowerThanMaxValue = (elementToCheck <= maxValue);

    cout << "Is the value " << elementToCheck << " greater or equal to " << minValue << " ? " << isGreaterThanMinValue << endl;
    cout << "Is the value " << elementToCheck << " lower or equal to " << maxValue << " ? " << isLowerThanMaxValue << endl;



}

Example 4

#include <iostream>

using namespace std;

main()
{
    /*
        0
        1
        0101 0110

        1 2 6 = 1 * 10 ^ 2 + 2 * 10 ^ 1 + 6 * 10 ^ 0 = 100 + 20 + 6

        1 0 1 0 = 2 ^ 3 + 2 ^ 1 = 8 + 2 = 10

        1 0 1 1 0 0 = 2 ^ 2 + 2 ^ 3 + 2 ^ 5 = 4 + 8 + 32 = 44
    */
    /*
        Bitwise AND - &
        Bitwise OR - |
        Bitwise NOT - ~ (tilde)
        Bitwise XOR - ^ (caret) eXclusive OR.
        0 0 0
        0 1 1
        1 0 1
        1 1 0
        Bitwise left shift <<
        Bitwise right shift >>
    */

    cout << (10 & 2) << endl;

    /*
        1 0 1 0
        0 0 1 0
        -------
        0 0 1 0
    */
    cout << (10 | 2) << endl;

    /*
        1 0 1 0
        0 0 1 0
        -------
        1 0 1 0
    */
    cout << (10 ^ 2) << endl;

    /*
        1 0 1 0
        0 0 1 0
        -------
        1 0 0 0
    */

    cout << (~10) << endl;

    /*
         000000000000000000000000000000000000 1 0 1 0
         111111111111111111111111111111111111 0 1 0 1
    */

    cout << (10 << 3) << endl; //this thing means that we are multiplying 10 by 2 raised to the power of 3
    /*
        000000000000000000000000000000000001 0 1 0 0
        20 - decimal notation
        40
    */

    cout << (10 >> 1) << endl; //this thing means that we are dividing 10 by 2 raised to the power of 3
    /*
        00000000000000000000000000000000000 0 1 0 1
        5
    */
}

Comment  Read more

1. Guessing Game

|

import random
true_number = random.randint(1, 49) # 1~49까지 랜덤 넘버
true_number
guess_number = int(input("Enter your guess between 1 and 49: "))

guess_number
while True:
    if guess_number == true_number:
        print('YOU ARE RIGHT! GOOD JOB!')
        break

    elif guess_number < true_number:
        print('YOUR GUESS IS LOW, TRY AGAIN')
        guess_number = int(input("Enter your guess between 1 and 49: "))

    elif guess_number > true_number:
        print('YOUR GUESS IS HIGH, TRY AGAIN')
        guess_number = int(input("Enter an integer from 1 and 49: "))

Comment  Read more

1.자료형 크기

|

  • 32비트 기준으로 자료형 크기 범위
  • OS 비트에 따라 컴파일러에서 자료형의 크기가 다르다.

  • OS(16bit/32bit,64bit) 크기 사용의 요점
    • int는 시스템 기본연산 단위를 사용한다. (16bit -> 2byte, 32bit => 4byte, 64=> 4byte)
    • 64bit에서 long형을 8byte로 확장하였다. (16bit=>4byte, 64bit => 8byte)
    • Byte가 느러난다는것은 bit 수에 따라 메모리 할당량이 늘어난다는 것이다.

아스키코드

Comment  Read more

Finally start Blog(开始博客)

|

석사 1년동안 하면서 배운 내용들을 차곡차곡 정리해야겠다라는 생각이 들어 시작하게 되었다. 블로그 시작하기 전에 어떤 블로그를 사용해야 될지 검색을 많이 하였고 사용도 해보았다. Django, Blogger 그리고 마지막 jekyll 끝으로 나에게 가장 맞는 블로그는 jekyll라고 생각이 되어 jekyll로 시작하였다. 블로그 Template은 Rats’go 님의 템플렛을 이용하였지만 사용하는데 있어 하루정도 시간이 걸린거 같다. 블로그는 공부하며 배운 내용들을 정리할 예정이며 일상생활 또한 기록을 할 예정이다.

I began to think that I would need to organize what I learned during my master’s year. Before openning of this blog, I searched a lot about what blog platform I should use. i tried Django, Blogger, jekyll then i felt The best blog for me was jekyll, so I started with jekyll. I use Blog Template from Rats’go’s template, but it seems to take a day to use. The blog will organize the lessons learned and record daily life. I do not doubt that this blog will become very important to my career.

我开始博客因为我感觉到我要亨利我在硕士学年期间学到的东西。在我们开这个博客之前,我搜索了很多关于我应该使用的博客平台。我使用了Django,Blogger和最后一个jekyll对我来说最好的博客是jekyll,所以我开始使用jekyll。博客模板使用Rats’go的模板,但似乎需要一天时间才能使用。该博客将记录学习的东西并记录日常生活。

Comment  Read more