class ShowIms {public:ShowIms(string _win_name) {win_name = _win_name;namedWindow(win_name, WINDOW_NORMAL | WINDOW_KEEPRATIO);//createButton("next", ShowIms::next, NULL);//createButton("prev", ShowIms::prev, NULL);}ShowIms() {destroyWindow(win_name);}void play(vector _ims, vector _names);static void next(int state, void* userdata);static void prev(int state, void* userdata);static int count;private:vector ims_title;string win_name;};void ShowIms::next(int state, void* userdata) {cout << "测试:下一个"<< endl;}void ShowIms::prev(int state, void* userdata) {cout << "测试:上一个" << endl;}int ShowIms::count = 0;void ShowIms::play(vector _ims, vector _names) {vector strs;if (_names.size() != 0) {CV_Assert(_ims.size() == _names.size());}else {for (size_t i = 0; i < _ims.size(); i++) {stringstream ss;string str;ss << i; ss >> str; _names.push_back(str);}}for (;;){count = count % _ims.size();imshow(win_name, _ims[count]);setWindowTitle(win_name, _names[count]);//count++;int ret = waitKey(0);cout << "current key is " << ret << endl;switch (ret){case 99:count++;break;case 122:if (0 == count)count = _ims.size() - 1;elsecount--;break;default:break;}if (27 == ret)break;}}int main(int argc, char** argv) {RNG& rng = theRNG();vector ims;for (int i = 0; i < 10; i++) {Mat im = cv::Mat(Size(600, 500), CV_8UC1, cv::Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)));ims.push_back(im);}vector strs;ShowIms ims_show("myshow");ims_show.play(ims, strs);}
测试
最新推荐文章于 2023-03-04 21:51:40 发布