2016-05-12 25 views
0

javaの実装はOpenCVです。私はMat構造体を作成し、その中にデータを埋め込み、サブマートを抽出してから、イメージ変換を適用したいと考えています。だから、javaに、私はpythonでopenCVを使ってMatを作成する

my_mat = new Mat(my_rows, my_cols, CvType.CV_8U); 
my_mat.put(0, 0, my_data); 
my_mat.submat(0, my_other_rows, 0, my_other_cols); 

を使用しかし、私はpythonさんOpenCVで働く何かを見つけることができませんでした。私はこのlinkが見つかりましたが、それは、OpenCVの1.1について

+0

なぜダウン投票ですか? – Newben

答えて

2

を壊れている:

あなたがそれを行うためにCreateMatを使用することができます:関数呼び出しは以下と等価である

Creates a matrix header and allocates the matrix data.

Python: cv.CreateMat(rows, cols, type) → mat 
    Parameters: 
     rows – Number of rows in the matrix 
     cols – Number of columns in the matrix 
     type – The type of the matrix elements in the form CV_<bit depth><S|U|F>C<number of channels> , where S=signed, U=unsigned, F=float. For example, CV _ 8UC1 means the elements are 8-bit unsigned and the there is 1 channel, and CV _ 32SC2 means the elements are 32-bit signed and there are 2 channels. 

コード:

CvMat* mat = cvCreateMatHeader(rows, cols, type); 
cvCreateData(mat); 

CV2インターフェースについて:Python用

新しいCV2インタフェースは、それらが単純な多次元配列で表されるような動作がはるかに簡単になりOpenCVの枠組みにnumpyアレイを統合します。 ここに例があります:

import numpy as np, cv 
vis = np.zeros((384, 836), np.float32) 
h,w = vis.shape 
vis2 = cv.CreateMat(h, w, cv.CV_32FC3) 
vis0 = cv.fromarray(vis) 
+0

ありがとうございます。問題は、私は 'AttributeError: 'module'オブジェクトに 'CreateMat''属性がありません。 – Newben

+0

あなたはcv/cv2を使っていますか? – Vtik

+0

私は 'OpenCV 3.0'を使用しています – Newben

関連する問題