1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| void ImageShow::ImageGenerateAndShow() { int fontFace = cv::FONT_HERSHEY_SIMPLEX; std::string text("HelloWorld");
double fontScale = 3; int thickness = 2 ;
int baseline=0; cv::Size textSize = cv::getTextSize(text, fontFace, fontScale, thickness, &baseline);
int fontHeight = textSize.height;
int nFullWidth = GetSystemMetrics(SM_CXSCREEN); int nFullHeight = GetSystemMetrics(SM_CYSCREEN);
Content *tent = new Content((nFullHeight*10/textSize.width), (nFullWidth*4/5)/(3*textSize.height/2)); while(!tent->ContentGenerate()); std::cout << "contentShow size: " << (*tent->contentShow).size() << std::endl; std::vector<std::string> ptext = *tent->contentShow; std::cout << "ptext size: " << ptext.size() << std::endl; for(int i=0; i<ptext.size(); i++) std::cout << ptext[i] << std::endl;
cv::Mat img(nFullWidth, nFullHeight, CV_8U, cv::Scalar::all(0)); cv::Mat imgdst(nFullHeight, nFullWidth, CV_8U, cv::Scalar::all(0));
cv::Point textOrg;
int i, pos=3*fontHeight; for(i=0; i<ptext.size()&&i*fontHeight+nFullHeight/5 + i*fontHeight/3 < img.rows*4/5; i=i+2) { textSize = cv::getTextSize(ptext[i], fontFace, fontScale, thickness, &baseline); textOrg.x = (img.cols-textSize.width)/2; textOrg.y = pos; cv::putText(img, ptext[i], textOrg, fontFace, fontScale, cv::Scalar::all(255), thickness, 8); pos += 3*fontHeight; } cv::flip(img, img, 0); cv::flip(img, img, 1);
if(ptext.size()%2) { i=i-3; pos = nFullWidth - textOrg.y + 5*fontHeight/2; } else{ --i; pos = nFullWidth - textOrg.y - fontHeight/2; } std::cout << "i= " << i << std::endl; for(; i>0; i=i-2) { std::cout << ptext[i] << std::endl; textSize = cv::getTextSize(ptext[i], fontFace, fontScale, thickness, &baseline); textOrg.x = (img.cols-textSize.width)/2; textOrg.y = pos; cv::putText(img, ptext[i], textOrg, fontFace, fontScale, cv::Scalar::all(255), thickness, 8); pos += 3*fontHeight; }
cv::flip(img, img, 0); cv::flip(img, img, 1); cv::transpose(img, imgdst); cv::flip(imgdst, imgdst, 0);
cv::imwrite("test5.jpg", imgdst); initShowWindow(); ImageShowing(imgdst); destroyShowWindow(); }
void ImageShow::initShowWindow() { cvNamedWindow("Projector Window", CV_WINDOW_NORMAL); cvSetWindowProperty("Projector Window", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN); }
void ImageShow::ImageShowing(cv::Mat img) { IplImage ipl_img = img; cvShowImage("Projector Window", &ipl_img); cvWaitKey(showTime); }
|