int main(int argc, char* argv[]) { // 共有する先と名前とサイズをあわせておく SharedCvMat shared_img("capture_image", 640, 480, 3, false); cv::Mat image; while(true) { // 共有メモリからイメージをダウンロード shared_img.download(image); cv::imshow("shared image", image); int c = cv::waitKey(33); if (c == 27) break; } return 0; }
int main(int argc, char* argv[]) { cv::Mat img(cv::Size(640, 480), CV_8UC3); SharedImage shared_img("testname", 640, 480); while (true) { draw(img); shared_img.upload(img); cv::Mat resized_img; cv::resize(img, resized_img, cv::Size(320, 240)); cv::imshow("SharedImage_OpenCV", resized_img); int c = cv::waitKey(1); if (c == 27) break; } cv::destroyAllWindows(); return 0; }
//-----------------------------------------------------------------// bool jpeg_io::load(utils::file_io& fin, const std::string& opt) { // とりあえず、ヘッダーの検査 if(probe(fin) == false) { return false; } struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr errmgr; // エラーのハンドリング cinfo.err = jpeg_std_error(&errmgr); errmgr.error_exit = error_exit_task; // 構造体の初期設定 jpeg_create_decompress(&cinfo); // file_io クラス設定 fio_jpeg_file_io_src(&cinfo, &fin); // ファイルの情報ヘッダの読込み error_code_ = 0; jpeg_read_header(&cinfo, TRUE); if(error_code_) { std::cout << "JPEG decode error: 'header'(" << error_code_ << ")" << std::endl; jpeg_destroy_decompress(&cinfo); return false; } // 解凍の開始 error_code_ = 0; jpeg_start_decompress(&cinfo); if(error_code_) { std::cout << "JPEG decode error: 'decompress'(" << error_code_ << ")" << std::endl; jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); return false; } /// cinfo.in_color_space if(cinfo.output_components == 1) { img_ = shared_img(new img_rgba8); img_->create(vtx::spos(cinfo.image_width, cinfo.image_height), true); } else if(cinfo.output_components == 3) { img_ = shared_img(new img_rgba8); img_->create(vtx::spos(cinfo.image_width, cinfo.image_height), true); } else if(cinfo.output_components == 4) { img_ = shared_img(new img_rgba8); img_->create(vtx::spos(cinfo.image_width, cinfo.image_height), true); } else { img_ = 0; std::cout << "JPEG decode error: Can not support components: " << static_cast<int>(cinfo.output_components) << std::endl; jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); return false; } prgl_ref_ = cinfo.image_height; prgl_pos_ = 0; unsigned char* line = new unsigned char[cinfo.output_width * cinfo.output_components]; unsigned char* lines[1]; lines[0] = &line[0]; vtx::spos pos; for(pos.y = 0; pos.y < cinfo.image_height; ++pos.y) { jpeg_read_scanlines(&cinfo, (JSAMPLE**)lines, 1); unsigned char* p = &line[0]; if(cinfo.output_components == 4) { for(pos.x = 0; pos.x < cinfo.image_width; ++pos.x) { img::rgba8 c; c.r = *p++; c.g = *p++; c.b = *p++; c.a = *p++; img_->put_pixel(pos, c); } } else if(cinfo.output_components == 3) { for(pos.x = 0; pos.x < cinfo.image_width; ++pos.x) { img::rgba8 c; c.r = *p++; c.g = *p++; c.b = *p++; c.a = 255; img_->put_pixel(pos, c); } } else if(cinfo.output_components == 1) { for(pos.x = 0; pos.x < cinfo.image_width; ++pos.x) { img::rgba8 c; c.b = c.g = c.r = *p++; c.a = 255; img_->put_pixel(pos, c); } } prgl_pos_ = pos.y; } delete[] line; jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); fio_src_ptr src = (fio_src_ptr)cinfo.src; if(src->err_empty) { return false; } else { return true; } }