logo logo-text login-icon
search_button
menu_button
menu_button
close_button
- [ ƽþ ] 丣 vs ѹα -
opencv Ҷ Ϸ double rad = atan2((double)dx, (double)dy); ̷ϸ ݾ ⸦ ϴµ Ǵ Ǵ Լ ?
2024-10-10 12:50 ȸ 40 õ 2 16
rank
opencv Ҷ Ϸ double rad = atan2((double)dx, (double)dy); ̷ϸ ݾ ⸦ ϴµ Ǵ Ǵ Լ ?
rank AIê

OpenCV ⸦ ϴ پ Լ ǰ ֽϴ. Ư cv::Sobel̳ cv::Scharr ȭ ϴ ͸ ֽϴ. ̷ Լ ̹ ⸦ Ͽ x y 踦 Ÿϴ.

, Sobel ͸ Ͽ ⸦ ϴ Դϴ:

#include 

using namespace cv;

int main() {
    Mat image = imread("image.jpg", IMREAD_GRAYSCALE);
    if (image.empty()) {
        return -1;
    }

    Mat grad_x, grad_y;
    Mat abs_grad_x, abs_grad_y;

    // Sobel ̿Ͽ x  y   
    Sobel(image, grad_x, CV_16S, 1, , 3);
    Sobel(image, grad_y, CV_16S, , 1, 3);

    // 밪 ȯ
    convertScaleAbs(grad_x, abs_grad_x);
    convertScaleAbs(grad_y, abs_grad_y);

    //  ũ 
    Mat grad;
    addWeighted(abs_grad_x, .5, abs_grad_y, .5, , grad);

    imshow("Gradient", grad);
    waitKey();
    return ;
}

Sobel Լ ̿ ⸦ , 밪 ȯϰ, ⸦ ļ ⸦ ðȭϰ ֽϴ. ̷ ⸦ ֽϴ.

ڱҰ ϴ.

🔥 HIT 10
۾ 2024.10.10 13:09
radian ִ¼ pt ˶ pt1.x ϴ pt1.y?
õ 0
AIê 2024.10.10 13:09
@

־ (pt) (radian) ̿ ش絵 (pt1) y ǥ Ϸ ﰢԼ ϸ ˴ϴ.

Ϲ ̿ ֽϴ:

  1. ־ ( \theta ) (radian) ֿ (pt) ǥ ( (x_, y_) ) , pt1 x ǥ ( x_1 )̶ ϸ,
  2. pt1.y ϴ:

[ y_1 = y_ + (x_1 - x_) \cdot \tan(\theta) ]

⼭ ( \tan(\theta) ) ش ⸦ Ÿ, ( y_ ) Ⱑ Ǵ y ǥ Դϴ.

־ pt ˰ , Ư x ǥ y ǥ ֽϴ.

õ 0
۾ 2024.10.10 13:09
ڵ
õ 0
AIê 2024.10.10 13:09
@

Ʒ ־ (pt) ش絵 x ǥ ϴ y ǥ ϴ C++ ڵ Դϴ:

#include 
#include  // tan, M_PI

using namespace std;

int main() {
    // ־  pt
    double pt_x = 2.; // pt x ǥ
    double pt_y = 3.; // pt y ǥ

    // ־  (radian)
    double angle_rad = M_PI / 4; // : 45 (radian)

    // pt1 x ǥ
    double pt1_x = 4.; // ϴ pt1 x ǥ

    // pt1 y ǥ 
    double pt1_y = pt_y + (pt1_x - pt_x) * tan(angle_rad);

    cout << "pt1 y ǥ: " << pt1_y << endl;

    return ;
}

ڵ ܰ踦 մϴ:

  1. Ǵ (pt) x, y ǥ մϴ.
  2. մϴ.
  3. ϴ x ǥ(pt1_x) մϴ.
  4. ־ pt1 y ǥ(pt1_y) մϴ.
  5. y ǥ մϴ.

45(/4 ) شϴ ⸦ Ͽ y ǥ ߽ϴ. Ͻô Ͽ Ͻø ˴ϴ.

õ 0
۾ 2024.10.10 13:20
˶  ?
õ 0
AIê 2024.10.10 13:20
@

˰ , ⸦ ϴ Լ ϸ մϴ. Ư ( \tan ) Լ Ͽ ⸦ ֽϴ.

( m ) ǵ˴ϴ:

[ m = \tan(\theta) ]

⼭ ( \theta ) ()Դϴ. C++ ڵ ⸦ ϴ ϴ:

#include 
#include  // tan, M_PI

using namespace std;

int main() {
    //    (: 45 -> /4)
    double angle_deg = 45.; //  
    double angle_rad = angle_deg * (M_PI / 180.); //  ȯ

    //  
    double slope = tan(angle_rad);

    cout << ": " << slope << endl;

    return ;
}

ڵ忡:

  1. Է¹ް, ̸ ȯմϴ.
  2. ȯ Ͽ ⸦ մϴ.
  3. ⸦ մϴ.

45 1 ˴ϴ. ٸ ؼ ⸦ ֽϴ.

õ 0
۾ 2024.10.10 13:21
˶  ?
õ 0
AIê 2024.10.10 13:21
@

( (x_1, y_1) ) ( (x_2, y_2) ) ־ , ϴ ⸦ ϰ, ̸ ֽϴ. ⸦ ũźƮ Լ Ͽ ȯմϴ.

ֽϴ:

[ \text{slope} = m = \frac{y_2 - y_1}{x_2 - x_1} ]

׷ ( \theta ) մϴ:

[ \theta = \tan^{-1}(m) ]

C++ ڵ ϸ ϴ:

#include 
#include  // atan2, M_PI

using namespace std;

int main() {
    //   
    double x1 = 2., y1 = 3.; // ù ° 
    double x2 = 5., y2 = 7.; //  ° 

    //  
    double deltaY = y2 - y1;
    double deltaX = x2 - x1;
    double slope = deltaY / deltaX;

    //    (atan2 )
    double angle_rad = atan2(deltaY, deltaX);

    //  
    cout << ": " << slope << endl;
    cout << "ȿ  : " << angle_rad << endl;

    return ;
}

ڵ忡:

  1. ǥ մϴ.
  2. y ǥ ̸ ( \Delta y ), x ǥ ̸ ( \Delta x ) մϴ.
  3. ⸦ մϴ.
  4. ũźƮ Լ atan2 Ͽ մϴ. atan2 Լ ( \Delta y ) ( \Delta x ) ڷ ޾ شϴ ֹǷ, и鿡 ùٸ ȯϴ ֽϴ.
  5. մϴ.

ֽϴ.

õ 0
۾ 2024.10.10 13:22
deltaX = x2 - x1 0̸?
õ 0
AIê 2024.10.10 13:22
@

( \Delta x = x_2 - x_1) ̶, ̴ x ǥ ٴ ǹմϴ. Ⱑ Ѵ밡 Ǹ, ˴ϴ. ǵ Ƿ, ũźƮ Լ atan2 Ͽ Ư ó ʿմϴ.

ǵ˴ϴ:

  • ( \Delta x = ): ( \Delta y ) :
    • ( \Delta y > ): ( \frac{\pi}{2} ) (90)
    • ( \Delta y < ): ( -\frac{\pi}{2} ) (-90)

, ڵ忡 ó ֽϴ:

#include 
#include  // atan2, M_PI

using namespace std;

int main() {
    //   
    double x1 = 2., y1 = 3.; // ù ° 
    double x2 = 2., y2 = 7.; //  °  (x1 x2 ϴ)
    
    //  
    double deltaY = y2 - y1;
    double deltaX = x2 - x1;

    double angle_rad;

    if (deltaX == ) {
        // x ǥ  
        if (deltaY > ) {
            angle_rad = M_PI / 2; //   
        } else if (deltaY < ) {
            angle_rad = -M_PI / 2; //   Ʒ
        } else {
            angle_rad = ; //     ()
        }
    } else {
        // atan2 ̿Ͽ  
        angle_rad = atan2(deltaY, deltaX);
    }

    //  
    cout << "ȿ  : " << angle_rad << endl;

    return ;
}

ڵ忡:

  1. x ǥ 츦 üũմϴ.
  2. ( \Delta y ) մϴ.
  3. x ǥ ٸ atan2 Ͽ մϴ.

̷ ó 쿡 ϰ ֽϴ.

õ 0
۾ 2024.10.10 13:30
˶ ?
õ 0
AIê 2024.10.10 13:30
@

־ ־ ,⸦ ϴ ϴ. źƮ Ͽ ֽϴ.

ùٸ ϸ ϴ:

[ \text{slope} = m = \tan(\theta) ]

⼭ ( \theta ) ־ ()Դϴ.

C++ ڵ ⸦ ϴ Ʒ ϴ:

#include 
#include  // tan

using namespace std;

int main() {
    // ־  ()
    double angle_rad = M_PI / 4; // : /4 (45)

    //  
    double slope = tan(angle_rad);

    //  
    cout << ": " << slope << endl;

    return ;
}

ڵ忡:

  1. մϴ.
  2. tan Լ Ͽ ⸦ մϴ.
  3. ⸦ մϴ.

( \frac{\pi}{4} ) (45) Ⱑ 1 ˴ϴ. ٸ ؼ ⸦ ֽϴ.

õ 0
۾ 2024.10.10 13:33
˶ ⸦ Ѱ ˶ ⸦ Ѱ ޶?
õ 0
AIê 2024.10.10 13:33
@

˰ ⸦ ˰ ⸦ ٸ ־ ̿ ֽϴ. ̸ ڼ ϰڽϴ.

  1. ˰ :

    • ( (x_1, y_1) ) ( (x_2, y_2) ) ־, ǵ˴ϴ: [ m = \frac{y_2 - y_1}{x_2 - x_1} ]
    • ϴ , ( \Delta y / \Delta x ) Ÿ, ־ ǵ ⸦ ݿմϴ.
  2. ˰ :

    • ˰ , ǵ˴ϴ: [ m = \tan(\theta) ]
    • ⼭ ( \theta ) Ư Ÿ Դϴ. κ ǵ մϴ.

:

  • : ˰ ִ 쿡 ־ , ̷κ ⸦ մϴ. ݸ ־ Ư Ÿ , ⿡ ġ ʿ ϴ.
  • ǥ ý: ⸦ ϴ 谡 ð ٸ ֽϴ. , Ư Ⱑ Ǿ ġ Ⱑ ġ ֽϴ.

, ⸦ , ˰ ִ Ǵ ֱ , ٸ Ÿ ֽϴ.

õ 0
۾ 2024.10.10 13:33
ڵ ˷
õ 0
AIê 2024.10.10 13:33
@

⸦ ϴ ڵ ⸦ ϴ ڵ带 ϴ ϰڽϴ. ڵ ⸦ ϰ, մϴ.

#include 
#include  // tan, atan2

using namespace std;

int main() {
    //   
    double x1 = 2., y1 = 3.; // ù ° 
    double x2 = 5., y2 = 7.; //  ° 

    //  κ  
    double deltaY = y2 - y1;
    double deltaX = x2 - x1;
    double slope_from_points;

    // Ⱑ ǵ ʴ  ó
    if (deltaX != ) {
        slope_from_points = deltaY / deltaX;
    } else {
        slope_from_points = INFINITY; //  
    }

    //  
    double angle_rad = atan2(deltaY, deltaX); //  κ  
    double slope_from_angle = tan(angle_rad); // κ 

    //  
    cout << " κ  : " << slope_from_points << endl;
    cout << "κ  : " << slope_from_angle << endl;

    return ;
}

ڵ

  1. : ( (x_1, y_1) ) ( (x_2, y_2) ) մϴ.
  2. :
    • ( \Delta y ) ( \Delta x ) մϴ.
    • ( m ) մϴ. ( \Delta x ) 쿡 Ⱑ ǵ Ƿ, INFINITY մϴ.
  3. :
    • atan2 Լ Ͽ κ մϴ.
    • κ ⸦ ٽ մϴ.
  4. : ⸦ մϴ.

ڵ ǵ 鿡 ⸦ ֵ մϴ.  ٸ Ȯ ֽϴ.

õ 0

⏰ ֽű (NEW)

ü û Ŀ ä

❤️‍🔥 HIT

ϱ

Ȩ | α | PC | ũ |
⼮üũ | Ʈå | Ʈ |

䷣ ΰ

ã ȸ
Ҽȷα