123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- //
- // LevelThumbTool.cpp
- // auto_fill_jewel_v3
- //
- // Created by Red on 2024/12/4.
- //
- #include "LevelThumbTool.hpp"
- #include <iostream>
- #include <sstream>
- using std::stringstream;
- using std::cout;
- using std::endl;
- void LevelThumbTool::makeThumb(string outpngname, vector<int>& plateIdArr,vector<ContourData::Point>& platePosiArr )
- {
- int visWid = 640 ;
- int visHei = 720 ;
- int canvasWid = visWid+270 ;
- int canvasHei = visHei+100 ;
-
- int x0 = 20 ;
- int y0 = 50 ;
-
- cv::Mat levelimage = cv::Mat::ones( canvasHei, canvasWid , CV_8UC3 );
- cv::Point p0(x0 ,y0 ) ;
- cv::Point p1(x0+visWid,y0+visHei) ;
- cv::rectangle(levelimage, p0, p1, cv::Scalar(191,191,191),2,cv::LINE_8) ;
- for(int ip = 0 ; ip < plateIdArr.size(); ++ ip ) {
- FillGlobalConfig::PlateItem* plate = FillGlobalConfig::getInstance()->getPlateItemById(plateIdArr[ip]) ;
- string pngName = string("./轮廓/sg_盘子轮廓/")+ plate->_pngName ;
- cv::Mat png = cv::imread(pngName) ;
-
- int x = platePosiArr[ip].x ;
- int y = platePosiArr[ip].y ;
- y = 720 - y ; //左下坐标转左上坐标
- x+=x0;
- y+=y0;
- int wid = plate->_bbwid ;
- int hei = plate->_bbhei ;
- x = x-wid/2 ;
- y = y-hei/2 ;
- //cout<<x<<","<<y<<","<<wid<<","<<hei <<" canvas " << levelimage.rows <<"," << levelimage.cols <<endl;
- png.copyTo( levelimage(cv::Rect(x,y,wid,hei)) ) ;
- }
- cv::imwrite(outpngname, levelimage) ;
- }
- void LevelThumbTool::drawthumb(
- string outname ,
- vector<tuple<int,vector<vector<FillResult>>>>& fillResultsArr,
- vector<ContourData::Point>& posiArr ) {
- vector<int> plateIdArr ;
- for(int ip = 0 ; ip < fillResultsArr.size();++ip ) {
- plateIdArr.push_back( std::get<0>(fillResultsArr[ip]) ) ;
- }
- makeThumb(outname, plateIdArr, posiArr) ;
- }
- void LevelThumbTool::makeThumb2(string outpngname, vector<tuple<int,vector<vector<FillResult>>>>& fillResultsArr,vector<ContourData::Point>& platePosiArr )
- {
- int visWid = 640 ;
- int visHei = 720 ;
- int canvasWid = visWid+270 ;
- int canvasHei = visHei+100 ;
-
- int x0 = 20 ;
- int y0 = 50 ;
-
- cv::Mat levelimage = cv::Mat::ones( canvasHei, canvasWid , CV_8UC3 );
- cv::Point p0(x0 ,y0 ) ;
- cv::Point p1(x0+visWid,y0+visHei) ;
- cv::rectangle(levelimage, p0, p1, cv::Scalar(191,191,191),2,cv::LINE_8) ;
- for(int ip = 0 ; ip < fillResultsArr.size(); ++ ip ) {
- int plateTypeId = std::get<0>( fillResultsArr[ip] ) ;
- int nlyr = (int) std::get<1>( fillResultsArr[ip] ).size() ;
-
- FillGlobalConfig::PlateItem* plate = FillGlobalConfig::getInstance()->getPlateItemById(plateTypeId) ;
- string pngName = string("./轮廓/sg_盘子轮廓/")+ plate->_pngName ;
- cv::Mat png = cv::imread(pngName) ;
-
- int x = platePosiArr[ip].x ;
- int y = platePosiArr[ip].y ;
- y = 720 - y ; //左下坐标转左上坐标
- x+=x0;
- y+=y0;
- int wid = plate->_bbwid ;
- int hei = plate->_bbhei ;
- x = x-wid/2 ;
- y = y-hei/2 ;
- //cout<<x<<","<<y<<","<<wid<<","<<hei <<" canvas " << levelimage.rows <<"," << levelimage.cols <<endl;
- png.copyTo( levelimage(cv::Rect(x,y,wid,hei)) ) ;
- //写入层数
- stringstream ss ;
- ss<<" x"<<nlyr ;
- cv::putText(levelimage, ss.str(), cv::Point(x+5,y+25), cv::FONT_HERSHEY_PLAIN, 1, cv::Scalar(103,101,238)) ;
- }
- cv::imwrite(outpngname, levelimage) ;
- }
|