cv::medianBlur(original, original, 3);
cv::Mat hsv; cv::cvtColor(original, hsv, cv::COLOR_RGB2HSV); if (layerType == LAYER_HSV) { *(cv::Mat*)matAddress = hsv; }
std::vector<cv::Mat> channels; cv::split(hsv, channels); cv::Mat minHueThreshold = channels[0] < lowerHue; if (layerType == LAYER_HUE_LOWER) { *(cv::Mat*)matAddress = minHueThreshold; } cv::Mat maxHueThreshold = channels[0] > upperHue; if (layerType == LAYER_HUE_UPPER) { *(cv::Mat*)matAddress = maxHueThreshold; } if (layerType == LAYER_HUE) { *(cv::Mat*)matAddress = minHueThreshold | maxHueThreshold; } cv::Mat saturationThreshold = channels[1] > minSaturation; if (layerType == LAYER_SATURATION) { *(cv::Mat*)matAddress = saturationThreshold; } cv::Mat valueThreshold = channels[2] > minValue; if (layerType == LAYER_VALUE) { *(cv::Mat*)matAddress = valueThreshold; } cv::Mat colorFiltered = (minHueThreshold | maxHueThreshold) & saturationThreshold & valueThreshold; if (layerType == LAYER_RED_FILTERED) { *(cv::Mat*)matAddress = colorFiltered; }
cv::Mat colorDilated; cv::dilate(colorFiltered, colorDilated, cv::Mat()); if (layerType == LAYER_DILATED) { *(cv::Mat*)matAddress = colorDilated; }
cv::SimpleBlobDetector::Params params; params.filterByColor = false; params.filterByConvexity = false; params.filterByInertia = false; params.filterByArea = true; // A = 254.46900494077 px^2 9 px params.minArea = 255; // A = 723822.94738709 px^2 480 px params.maxArea = 723823; params.filterByCircularity = true; params.minCircularity = 0.85f; cv::Ptr<cv::SimpleBlobDetector> detector = cv::SimpleBlobDetector::create(params); std::vector<cv::KeyPoint> keyPoints; detector->detect(colorDilated, keyPoints);
extern "C" JNIEXPORT void JNICALL Java_ru_dksta_prohibitingsigndetector_ActivityMain_rotation(JNIEnv /* *env */, jclass /* activity */, jlong matAddress, jint angle) { CV_Assert(angle % 90 == 0 && angle <= 360 && angle >= -360); cv::Mat* mat = (cv::Mat*) matAddress; if (angle == 180 || angle == -180) { cv::flip(*mat, *mat, -1); } }
extern "C" JNIEXPORT void JNICALL Java_ru_dksta_prohibitingsigndetector_ActivityMain_saltPepperNoise(JNIEnv /* *env */, jclass /* activity */, jlong matAddress) { cv::Mat* mat = (cv::Mat*) matAddress; cv::Mat noise = cv::Mat::zeros((*mat).rows, (*mat).cols, CV_8U); cv::randu(noise, 0, 255); cv::Mat black = noise < 30; cv::Mat white = noise > 225; (*mat).setTo(255, white); (*mat).setTo(0, black); }
if (secondView) { cv::Mat miniView = colorDilated.clone(); cv::cvtColor(miniView, miniView, cv::COLOR_GRAY2RGB); cv::resize(miniView, miniView, cv::Size(), 0.6, 0.6, cv::INTER_LINEAR); cv::Size miniSize = miniView.size(); cv::Size maxSize = original.size(); int startY = maxSize.height - miniSize.height; for (int y = startY; y < maxSize.height; y++) { for (int x = 0; x < miniSize.width; x++) { (*(cv::Mat*)matAddress).at<cv::Vec3b>(cv::Point(x, y)) = miniView.at<cv::Vec3b>(cv::Point(x, y - startY)); } } }
cv::Mat* mat = (cv::Mat*)matAddress; int textStartY = TEXT_LINE_HEIGHT; std::ostringstream output; output << std::setw(2) << std::setfill('0') << fpsCount << " FPS"; cv::putText(*mat, output.str(), cv::Point(TEXT_START_X, textStartY), FONT_FACE, FONT_SCALE, GREEN, TEXT_THICKNESS); output.seekp(0); textStartY += TEXT_LINE_HEIGHT; cv::putText(*mat, getLayerTypeDesc(layerType), cv::Point(TEXT_START_X, textStartY), FONT_FACE, FONT_SCALE, GREEN, TEXT_THICKNESS);
Source: https://habr.com/ru/post/339506/
All Articles