質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Q&A

1回答

1628閲覧

OpenCVのcv::undistortPointsに座標情報を渡したいです.

koomint

総合スコア3

OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

0グッド

0クリップ

投稿2022/01/16 12:18

OpenCVのcv::undistortPointsという画像歪み補正後の点を求める関数に,テキストファイルから読み込んだ座標を渡したいです.

自分がかいたコードを次に示します.発生したエラーもその次に示します.
問題なのは~~~~の後の部分です.
OpenCVのcv::undistortPointsの公式HP

c++

1#include <iostream> 2#include <fstream> 3#include <vector> 4#include <cmath> 5#include <opencv2/opencv.hpp> 6#include <stdlib.h> 7 8//テキストファイルの指定行を取り出すために一旦全て読み込み 9int getStrFromText(std::string filename, std::vector<std::string> &vstr) 10{ 11 std::ifstream ifs(filename); 12 13 if (!ifs) 14 { 15 std::cout << "error :>> failed to open the text file." << std::endl; 16 return 1; 17 } 18 19 std::string tmp; 20 while (getline(ifs, tmp)) 21 vstr.push_back(tmp); 22 23 return 0; 24} 25 26int main(int argc, char *argv[]){ 27 28 //argcはプログラムの引数の数 29 //./bird image.jpgで実行したとしたらargv[0] = bird,argv[1] = image.jpgでargcは2 30 if(argc != 5){ 31 std::cout << "\nERROR: too few parameters\n"; 32 //help(argv); 33 return -1; 34 } 35 36 //atoiは文字列を数値に変換 37 int board_w = atoi(argv[1]); 38 int board_h = atoi(argv[2]); 39 int board_n = board_w * board_h; 40 cv::Size board_sz = cv::Size2i(board_w, board_h); 41 //cv::Size board_sz(board_w, board_h); 42 //読み込みでファイルを開く 43 cv::FileStorage fs(argv[3], cv::FileStorage::READ); 44 cv::Mat intrinsic, distortion; 45 46 fs["camera_matrix"] >> intrinsic; 47 fs["distortion_coefficients"] >> distortion; 48 if(!fs.isOpened() || intrinsic.empty() || distortion.empty()){ 49 std::cout << "Error: Couldn't load intrinsic parameters from " 50 << argv[3] << std::endl; 51 return -1; 52 } 53 fs.release(); 54 55//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 56 57//点の歪み補正と鳥瞰変換 58 const std::vector<cv::Point2f> dstdata1, dstdata2, dstdata3, dstdata4, dstdata11, dstdata22, dstdata33, dstdata44; 59 //float dstdata1[1][2], dstdata2[1][2], dstdata3[1][2], dstdata4[1][2], dstdata11[1][2], dstdata22[1][2], dstdata33[1][2], dstdata44[1][2]; 60 cv::Mat P; 61 std::ifstream file1("../ryoiki/1x.txt"); //いくつかのある点のx座標が改行で縦に並んでいるテキストファイル 62 std::string line1; 63 64//指定行読み込むために一旦全て読み込む 65 std::vector<std::string> vstr1; 66 getStrFromText("../ryoiki/1y.txt", vstr1); //いくつかのある点のy座標が改行で縦に並んでいるテキストファイル 67//1x.txtファイルと同じ行を読み込むためのカウント 68 int count1 = 0; 69 while (std::getline(file1, line1)) { // 1行ずつ読み込む 70 std::vector<cv::Point2f> data1(stof(line1), stof(vstr1[count1])); 71//画像の歪み補正後の点座標を求める 72 cv::undistortPoints(data1, dstdata1, intrinsic, distortion, P = intrinsic); 73//俯瞰変換後の点の座標を求める 74//Hの値は事前にわかっています 75 cv::perspectiveTransform(dstdata1, dstdata11, H); 76 std::ofstream ob1; 77 ob1.open("./apps/bird/dstryo1xy.txt", std::ios::app); 78//ここでob1に出力する予定 79 count1 += 1; 80 ob1.close(); 81 82 } 83

error

1error: no matching constructor for initialization of 'std::vector<cv::Point2f>' (aka 'vector<Point_<float>>') 2 std::vector<cv::Point2f> data1(stof(line1), stof(vstr1[count1])); 3 4error: no matching constructor for initialization of 'std::vector<cv::Point2f>' (aka 'vector<Point_<float>>') 5 std::vector<cv::Point2f> data2(stof(line2), stof(vstr2[count2])); 6 7error: no matching constructor for initialization of 'std::vector<cv::Point2f>' (aka 'vector<Point_<float>>') 8 std::vector<cv::Point2f> data3(stof(line3), stof(vstr3[count3])); 9 10error: no matching constructor for initialization of 'std::vector<cv::Point2f>' (aka 'vector<Point_<float>>') 11 std::vector<cv::Point2f> data4(stof(line4), stof(vstr4[count4]));

ファイルから読み込んだ値をfloat型にしていますが型が違うと返されてしまいます.
どなたかご教授ください.

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

std::vector<cv::Point2f> data1(stof(line1), stof(vstr1[count1]));

float値をふたつvectorのコンストラクタに与えてますが、何を意図したものですか?
※ これで「ふたつのfloatからcv::Point2fがひとつできてvectorに挿入される」と思っているなら大間違いです。

投稿2022/01/17 08:04

episteme

総合スコア16614

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問