void SpriteBatch::draw(const Vector3& dst, float width, float height, float u1, float v1, float u2, float v2, const Vector4& color, const Vector2& rotationPoint, float rotationAngle) { // Expand dst by scale into 4 points. float x2 = dst.x + width; float y2 = dst.y + height; Vector2 upLeft(dst.x, dst.y); Vector2 upRight(x2, dst.y); Vector2 downLeft(dst.x, y2); Vector2 downRight(x2, y2); // Rotate points around rotationAxis by rotationAngle. Vector2 pivotPoint(rotationPoint); pivotPoint.x *= width; pivotPoint.y *= height; pivotPoint.x += dst.x; pivotPoint.y += dst.y; upLeft.rotate(pivotPoint, rotationAngle); upRight.rotate(pivotPoint, rotationAngle); downLeft.rotate(pivotPoint, rotationAngle); downRight.rotate(pivotPoint, rotationAngle); // Write sprite vertex data. static SpriteVertex v[4]; ADD_SPRITE_VERTEX(v[0], upLeft.x, upLeft.y, dst.z, u1, v1, color.x, color.y, color.z, color.w); ADD_SPRITE_VERTEX(v[1], upRight.x, upRight.y, dst.z, u1, v2, color.x, color.y, color.z, color.w); ADD_SPRITE_VERTEX(v[2], downLeft.x, downLeft.y, dst.z, u2, v1, color.x, color.y, color.z, color.w); ADD_SPRITE_VERTEX(v[3], downRight.x, downRight.y, dst.z, u2, v2, color.x, color.y, color.z, color.w); static unsigned short indices[4] = { 0, 1, 2, 3 }; _batch->add(v, 4, indices, 4); }
void tag_recognition::cutWords(cv::Mat wordsMask, cv::Mat rawDst, cv::Mat &word1, cv::Mat &word2) { std::vector < std::vector<cv::Point2f> > rotatedBlobs; cv::normalize(wordsMask,wordsMask,0,1,cv::NORM_MINMAX); this->findBlobs(wordsMask,rotatedBlobs); rotatedBlobs = this->removeImpossibleBlobs(rotatedBlobs); // qDebug() << rotatedBlobs.size(); if(rotatedBlobs.size() < 2) { cv::normalize(wordsMask,wordsMask,0,255,cv::NORM_MINMAX); // cv::imshow("WTF",wordsMask); word1 = cv::Mat::zeros(1,1,CV_8UC1); word2 = cv::Mat::zeros(1,1,CV_8UC1); return; } std::vector<cv::Point2f> topLeft(rotatedBlobs.size()); std::vector<cv::Point2f> downRight(rotatedBlobs.size()); for(int i = 0; i < rotatedBlobs.size(); i++) { topLeft[i] = cv::Point2f(tagSize,tagSize); downRight[i] = cv::Point2f(0,0); for(int j=0; j < rotatedBlobs[i].size(); j++) { if(topLeft[i].x > rotatedBlobs[i][j].x) topLeft[i].x = rotatedBlobs[i][j].x; if(topLeft[i].y > rotatedBlobs[i][j].y) topLeft[i].y = rotatedBlobs[i][j].y; if(downRight[i].x < rotatedBlobs[i][j].x) downRight[i].x = rotatedBlobs[i][j].x; if(downRight[i].y < rotatedBlobs[i][j].y) downRight[i].y = rotatedBlobs[i][j].y; } // qDebug() << topLeft.x << topLeft.y << downRight.x << downRight.y; // cv::imshow(std::to_string(i),dst); } if(topLeft[0].x < topLeft[1].x) { cv::getRectSubPix(rawDst,cv::Size(downRight[0].x-topLeft[0].x+4,downRight[0].y-topLeft[0].y+4),(downRight[0]+topLeft[0])/2,word1); cv::getRectSubPix(rawDst,cv::Size(downRight[1].x-topLeft[1].x+4,downRight[1].y-topLeft[1].y+4),(downRight[1]+topLeft[1])/2,word2); } else { cv::getRectSubPix(rawDst,cv::Size(downRight[0].x-topLeft[0].x+4,downRight[0].y-topLeft[0].y+4),(downRight[0]+topLeft[0])/2,word2); cv::getRectSubPix(rawDst,cv::Size(downRight[1].x-topLeft[1].x+4,downRight[1].y-topLeft[1].y+4),(downRight[1]+topLeft[1])/2,word1); } }
void SpriteBatch::draw(float x, float y, float z, float width, float height, float u1, float v1, float u2, float v2, const Vector4& color, const Vector2& rotationPoint, float rotationAngle, bool positionIsCenter) { // Treat the given position as the center if the user specified it as such. if (positionIsCenter) { x -= 0.5f * width; y -= 0.5f * height; } // Expand the destination position by scale into 4 points. float x2 = x + width; float y2 = y + height; Vector2 upLeft(x, y); Vector2 upRight(x2, y); Vector2 downLeft(x, y2); Vector2 downRight(x2, y2); // Rotate points around rotationAxis by rotationAngle. if (rotationAngle != 0) { Vector2 pivotPoint(rotationPoint); pivotPoint.x *= width; pivotPoint.y *= height; pivotPoint.x += x; pivotPoint.y += y; upLeft.rotate(pivotPoint, rotationAngle); upRight.rotate(pivotPoint, rotationAngle); downLeft.rotate(pivotPoint, rotationAngle); downRight.rotate(pivotPoint, rotationAngle); } // Write sprite vertex data. static SpriteVertex v[4]; SPRITE_ADD_VERTEX(v[0], downLeft.x, downLeft.y, z, u1, v1, color.x, color.y, color.z, color.w); SPRITE_ADD_VERTEX(v[1], upLeft.x, upLeft.y, z, u1, v2, color.x, color.y, color.z, color.w); SPRITE_ADD_VERTEX(v[2], downRight.x, downRight.y, z, u2, v1, color.x, color.y, color.z, color.w); SPRITE_ADD_VERTEX(v[3], upRight.x, upRight.y, z, u2, v2, color.x, color.y, color.z, color.w); static unsigned short indices[4] = { 0, 1, 2, 3 }; _batch->add(v, 4, indices, 4); }