opencv颜色分割_使用opencv进行颜色分割

opencv颜色分割

Back in the September of 2019, one of the first few tasks I took up after starting my higher studies, was to identify co-ordinates for some underwater buoys which led me to huge new domain of Computer Sciences namely Image Processing.

早在2019年9月,我就开始了高等学业后承担的头几个任务之一是为某些水下浮标确定坐标,这使我进入了计算机科学的新领域-即图像处理。

One of the most prominent names in this trade is OpenCV, a python library written for the sole purpose of taking up Computer Vision challenges.

在这个行业中最著名的名称之一是OpenCV,这是一个专门为应对计算机视觉挑战而编写的python库。

Of the several tasks like filtering, transforming, resizing and what not, segmentation is a rather important task that can be done using OpenCV which is a step towards advanced concepts like classification and detection. Segmentation is the task of dividing different objects in sections corresponding to either a same object type or color.

在诸如过滤,变换,调整大小之类的若干任务中,分段是一项相当重要的任务,可以使用OpenCV完成,这是朝着高级概念(如分类和检测)迈出的一步。 分割是将不同的对象划分为与相同对象类型或颜色相对应的部分的任务。

There are majorly 3 different types of segmentation in computer vision:-

计算机视觉中主要有3种不同的细分类型:

  1. Color Segmentation or Thresholding Segmentation

    颜色分割或阈值分割
  2. Semantic Segmentation

    语义分割
  3. Edge Detection

    边缘检测

As suggested in the title I am going to be talking about color segmentation particularly using OpenCV. You might ask why use OpenCV a 21 year old library when we have tools like Caffe and Keras at our disposal.

如标题中所建议,我将谈论颜色分割,尤其是使用OpenCV颜色分割。 您可能会问,当我们拥有像Caffe和Keras这样的工具时,为什么要使用拥有21年历史的OpenCV库。

OpenCV however lagging in terms of accuracy is a much faster method as compared to the modern SOTA DL methods like Caffe and Keras.

但是,与Caffe和Keras等现代SOTA DL方法相比,OpenCV在准确性方面的落后是一个快得多的方法。

Image for post
CPU performance comparison across frameworks on Image Classification tasks
跨框架进行图像分类任务的CPU性能比较

This celerity of OpenCV doesn’t stop here, one of the most famous neural network framework also somewhat lags in terms of object detection namely Object detection using YOLOv3

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于在 Android 上使用 OpenCV 进行 RGB 色域的颜色分割,你可以按照以下步骤进行操作: 1. 首先,确保你已经在 Android 项目中集成了 OpenCV 库。你可以在 OpenCV 官方网站上找到相关的文档和指南。 2. 在你的代码中,导入必要的 OpenCV 类和方法: ```java import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.JavaCameraView; import org.opencv.android.Utils; import org.opencv.core.Mat; import org.opencv.core.MatOfRect; import org.opencv.core.Rect; import org.opencv.core.Scalar; import org.opencv.core.Size; import org.opencv.imgproc.Imgproc; ``` 3. 在你的 Activity 中,实现 `CameraBridgeViewBase.CvCameraViewListener2` 接口,并初始化相机视图: ```java public class MainActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 { private JavaCameraView javaCameraView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); javaCameraView = (JavaCameraView) findViewById(R.id.java_camera_view); javaCameraView.setVisibility(SurfaceView.VISIBLE); javaCameraView.setCvCameraViewListener(this); } } ``` 4. 实现相机视图的回调方法,在 `onCameraFrame()` 方法中进行图像处理: ```java @Override public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) { Mat rgba = inputFrame.rgba(); // 将图像转换成 HSV 色域 Mat hsv = new Mat(); Imgproc.cvtColor(rgba, hsv, Imgproc.COLOR_RGB2HSV); // 颜色阈值,通过调整下面两个 Scalar 的值来选择特定颜色范围 Scalar lower = new Scalar(0, 100, 100); Scalar upper = new Scalar(10, 255, 255); // 对图像进行颜色分割 Mat mask = new Mat(); Core.inRange(hsv, lower, upper, mask); // 对分割结果进行处理,例如形态学操作或轮廓检测等 return rgba; } ``` 在上述代码中,我们首先将图像转换成 HSV 色域,然后通过调整 `lower` 和 `upper` 的值来选择特定的颜色范围,再使用 `Core.inRange()` 方法对图像进行颜色分割。你还可以根据需求对分割结果进行进一步的处理,例如应用形态学操作或进行轮廓检测等。 请注意,这只是一个简单的示例,你可能需要根据你的具体需求进行更多的图像处理和调整。同时,确保你已经在 AndroidManifest.xml 文件中添加了相机权限。 希望这能帮到你!如果有任何问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值