Giter VIP home page Giter VIP logo

my_notebook's Introduction

第一个笔记本

#include <opencv2/opencv.hpp>


int main() {

	std::vector<cv::String> file_names;

	cv::glob("images/", file_names);
	
	int cnt = 0;
	for (auto it = file_names.begin(); it != file_names.end(); ++it) {
		cv::Mat src_image, hsv_image, maskimg;

		src_image = cv::imread(*it);

		cv::cvtColor(src_image, hsv_image, CV_BGR2HSV);
		
		cv::inRange(hsv_image, cv::Scalar(0, 43, 46), cv::Scalar(34, 255, 255), maskimg);

		std::vector<std::vector<cv::Point>> contours;
		
		cv::findContours(maskimg, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);

		for (int i = 0; i < contours.size(); i++) {

			float area = cv::contourArea(contours[i]);

			cv::Scalar color;

			if (area < 100.0) {
				color = cv::Scalar(255, 0, 0);
			}
			else{
				color = cv::Scalar(0, 255, 0);
				cv::Rect rect = cv::boundingRect(contours[i]);
				cv::rectangle(src_image, rect, color,3);
			}

			//cv::drawContours(src_image, contours, i, color,-1);
		}
		
		cv::imwrite("res/"+std::to_string(cnt) + ".jpg",src_image);
		cnt++;
		//
	}

	return 0;
}

my_notebook's People

Contributors

dx111 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.