私はthe documentation for cv2.transformを理解していません。誰かが同情して、(Pythonで)どうか説明してくれますか?opencv(Python)の点のリストに変換行列を適用する
私はそれが
# this is clumsy, I have to extend each vector,
# apply the matrix to each extended vector,
# and turn the list of transformed vectors into an numpy array
extendedpolygon = np.hstack([polygon,np.ones((3,1))])
rotatedpolygon = np.int32([M.dot(x) for x in extendedpolygon])
cv2.fillConvexPoly(img,rotatedpolygon,(127))
私が好きな描く
import numpy as np
import cv2
dx,dy = 400,400
centre = dx//2,dy//2
img = np.zeros((dy,dx),np.uint8)
# construct a long thin triangle with the apex at the centre of the image
polygon = np.array([(0,0),(100,10),(100,-10)],np.int32)
polygon += np.int32(centre)
# draw the filled-in polygon and then rotate the image
cv2.fillConvexPoly(img,polygon,(255))
M = cv2.getRotationMatrix2D(centre,20,1) # M.shape = (2, 3)
rotatedimage = cv2.warpAffine(img,M,img.shape)
は、私は、最初のポリゴンを回転させたい画像を、ポリゴンを描画でそれを埋めて、回転コードを持っています1つの関数呼び出しで行いますが、それを正しく取得できません。
# both of these calls produce the same error
cv2.transform(polygon,M)
cv2.transform(polygon.T,M)
# OpenCV Error: Assertion failed (scn == m.cols || scn + 1 == m.cols) in transform, file /home/david/opencv/modules/core/src/matmul.cpp, line 1947
私はそれがフレーズ "src - m.colsまたはm.cols-1と同じ数のチャネル(1〜4)が必要な入力配列です。私は多角形だと思った。別々のチャンネルとしてxとyの部分を持つ3つの座標が適格となるが、悲しいことではない。
私は、同じ質問がC++に求められていることを知っています。私はPythonで回答したいと思います。
これはヒントでしたか? M = cv2.getRotationMatrix2D(center、20,1)#M.shape =(2,3) 私はポリゴンの各ベクトルにエントリを追加しなければならなかったのです計算することができました [拡張ポリゴンのxのM.dot(x)] M.shape =(2,3)はM.row = 2、M.col = 3を意味すると私は考えています。エラーメッセージです。 –
は、ポイントの書式設定の例です。私はpython/numpyをよく知らないので、フォーマットを解釈するのを手伝ってはいけません... http://dsp.stackexchange.com/questions/38626/image-preprocessing-for-facial-detection-embedding-clustering-パイプラインは、あなたが探しているものでなければなりません。 – Micka
ありがとうミカ、私は使用の例を探したが、見つけられなかった。 –