Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,27 @@
#ifndef PROCESSING_FLOODFILLALGORITHM_H_
#define PROCESSING_FLOODFILLALGORITHM_H_
#include <opencv2/opencv.hpp>
#include <string.h>
#include <queue>
using namespace cv;
using namespace std;
class FloodFillAlgorithm {
public:
FloodFillAlgorithm(Mat* image) :
image(image) {
}
virtual ~FloodFillAlgorithm();
void flood(Point startPoint, Scalar tgtColor, Scalar loDiff);
void flood(Point startPoint, Mat* tgtMat);
protected:
Mat* image;
private:
bool insideImage(Point p);
};
#endif /* PROCESSING_FLOODFILLALGORITHM_H_ */

View file

@ -0,0 +1,43 @@
#include "FloodFillAlgorithm.h"
FloodFillAlgorithm::~FloodFillAlgorithm() {
}
void FloodFillAlgorithm::flood(Point startPoint, Scalar tgtColor, Scalar loDiff) {
floodFill(*image, startPoint, tgtColor, 0, loDiff);
}
void FloodFillAlgorithm::flood(Point startPoint, Mat* tgtMat) {
if (!insideImage(startPoint))
return;
Vec3b srcColor = image->at<Vec3b>(startPoint);
if (image->at<Vec3b>(startPoint) == srcColor) {
queue<Point> pointQueue;
pointQueue.push(startPoint);
while (!pointQueue.empty()) {
Point p = pointQueue.front();
pointQueue.pop();
if (insideImage(p)) {
if ((image->at<Vec3b>(p) == srcColor)) {
image->at<Vec3b>(p) = tgtMat->at<Vec3b>(p);
pointQueue.push(Point(p.x + 1, p.y));
pointQueue.push(Point(p.x - 1, p.y));
pointQueue.push(Point(p.x, p.y + 1));
pointQueue.push(Point(p.x, p.y - 1));
}
}
}
}
}
bool FloodFillAlgorithm::insideImage(Point p) {
return (p.x >= 0) && (p.x < image->size().width) && (p.y >= 0) && (p.y < image->size().height);
}

View file

@ -0,0 +1,25 @@
/*REXX program demonstrates a method to perform a flood fill of an area. */
black= '000000000000000000000000'b /*define the black color (using bits).*/
red = '000000000000000011111111'b /* " " red " " " */
green= '000000001111111100000000'b /* " " green " " " */
white= '111111111111111111111111'b /* " " white " " " */
/*image is defined to the test image. */
hx=125; hy=125 /*define limits (x,Y) for the image. */
area=white; call fill 125, 25, red /*fill the white area in red. */
area=black; call fill 125, 125, green /*fill the center orb in green. */
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
fill: procedure expose image. hx hy area; parse arg x,y,fill_color
if x<1 | x>hx | y<1 | y>hy then return /*X or Y are outside of the image area*/
pixel=@(x,y) /*obtain the color of the X,Y pixel. */
if pixel\==area then return /*the pixel has already been filled */
/*with the fill_color, or we are not */
/*within the area to be filled. */
image.x.y=fill_color /*color desired area with fill_color. */
pixel=@(x ,y-1); if pixel==area then call fill x , y-1, fill_color /*north*/
pixel=@(x-1,y ); if pixel==area then call fill x-1, y , fill_color /*west */
pixel=@(x+1,y ); if pixel==area then call fill x+1, y , fill_color /*east */
pixel=@(x ,y+1); if pixel==area then call fill x , y+1, fill_color /*south*/
return
/*────────────────────────────────────────────────────────────────────────────*/
@: parse arg $x,$y; return image.$x.$y /*return with color of the X,Y pixel.*/