第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

沿 y 軸逐行旋轉(zhuǎn)(對齊)圖像

沿 y 軸逐行旋轉(zhuǎn)(對齊)圖像

小唯快跑啊 2022-10-25 10:28:35
我正在嘗試旋轉(zhuǎn)(對齊)圖像,其中P1包含P2沿y-axis原圖:注:綠色區(qū)域代表原圖結(jié)果應(yīng)該是:注:紅色區(qū)域代表旋轉(zhuǎn)后的原圖所以我需要計算由P1(x1,y1)andP2(x2,y2)和 by定義的線之間的角度y-axis,我的代碼是:import cv2import numpy as npfrom math import *import mathimport imutilsheight = 500width = 500original_image = np.zeros((height,width,3), np.uint8)original_image[:] = (0,255,0)x1 = 400y1 = 50P1 = (x1, y1)x2 = 100y2 = 300P2 = (x2, y2)cv2.line(original_image, P1, P2, (0, 0, 0), 3)deltaY = y1 - y2deltaX = x1 - x2angleInDegrees = atan2(deltaY, deltaX) * 180 / math.piprint(angleInDegrees)rotated_image = imutils.rotate_bound(original_image, angleInDegrees)cv2.imshow("Original", original_image)cv2.imshow("Rotated", rotated_image)cv2.waitKey(0)但是我的rotated_image 沒有正確對齊結(jié)果如下:我應(yīng)該如何解決它?
查看完整描述

1 回答

?
POPMUISE

TA貢獻(xiàn)1765條經(jīng)驗 獲得超5個贊

首先,您正在計算錯誤的角度。您正在計算的角度介于起源于原點并結(jié)束于 P1 的向量與起源于原點并結(jié)束于 P2 的向量之間。


您需要的角度介于從 P1 開始到 P2 結(jié)束[P2-P1]的向量與表示 y 軸方向的向量之間,即[0, 1].


其次,您必須考慮到您的原點位于左上角,因此您需要在計算后反映角度。


import cv2

import numpy as np

from math import *

import math

import imutils



height = 500

width  = 500


original_image = np.zeros((height,width,3), np.uint8)

original_image[:] = (0,255,0)


x1 = 400 

y1 = 50


P1 = np.array([x1, y1])


x2 = 100

y2 = 300


P2 = np.array([x2, y2])


# checks orientation of p vector & selects appropriate y_axis_vector

if (P2[1] - P1[1]) < 0:

    y_axis_vector = np.array([0, -1])

else:

    y_axis_vector = np.array([0, 1])


if (P2[0] - P1[0]) < 0 and (P2[1] - P1[1]) :

    y_axis_vector = np.array([0, 1])


p_unit_vector = (P2 - P1) / np.linalg.norm(P2-P1)

angle_p_y     = np.arccos(np.dot(p_unit_vector, y_axis_vector)) * 180 /math.pi


cv2.line(original_image, tuple(P1), tuple(P2), (0, 0, 0), 3)



print(angle_p_y)

print (P2-P1)



rotated_image = imutils.rotate_bound(original_image, -angle_p_y)


cv2.imshow("Original", original_image)

cv2.imshow("Rotated", rotated_image)

cv2.waitKey(0)

http://img1.sycdn.imooc.com//63574a550001310106270663.jpg

http://img1.sycdn.imooc.com//63574a6100019fc406600687.jpg

查看完整回答
反對 回復(fù) 2022-10-25
  • 1 回答
  • 0 關(guān)注
  • 131 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號