opencv 创建图像

This project stemmed from my predilection of the visual arts — as a computing student, I’ve always envied art students in their studios with splodges of colors and pristine white canvases. However, when I’m faced with a blank canvas and a (few) bottle(s) of paint, I don’t know where to start. Without the hours of training Art students have, I simply can’t go very far unless I’m following some Bob Ross tutorial. That’s why I’ve decided to explore and see if I can code something that will enable me to create art “automatically”.

这个项目源于我对视觉艺术的偏爱-作为一名计算机专业的学生,​​我总是在他们的工作室里用色彩斑p的原始画布和白色的原始画布羡慕艺术学生。 但是,当我面对一块空白的画布和几瓶油漆时,我不知道从哪里开始。 如果没有美术专业学生的训练,除非我正在听一些Bob Ross的教程,否则我走不了多远。 这就是为什么我决定探索并查看是否可以编写使我能够“自动”创作艺术作品的原因。

I did this project a looong time ago for my final year project when I wanted to create some software program that can allow its users to sketch something stickman-like on a pre-selected background, select the category of what was drawn, and the programme will intelligently figure out which image to poisson-blend in. After that, the user can also select a neural transfer style to be applied on the image.

我在不久前的最后一个项目中做了这个项目,当时我想创建一些软件程序,该程序可以让用户在预选的背景上绘制类似于stickman的东西,选择绘制的类别,然后选择该程序会智能地找出要进行泊松混合的图像。此后,用户还可以选择要应用于图像的神经传递样式。

So in this article I will be giving a brief walkthrough of this project. Because there are many parts to it, I won’t be going in-depth with the technical implementations. However, if you’d like me to do so, leave a comment and let me know! :)

因此,在本文中,我将简要介绍该项目。 因为涉及到很多部分,所以我不会深入探讨技术实现。 但是,如果您希望我这样做,请发表评论并告诉我! :)

第1部分-背景图片的选择 (Part 1 — Selection of the background image)

Because I wanted the user to have a range of images to choose from, I’ve coded a python script that acted as an image search engine. If an image is selected as the user browses through a range of available background images, similar looking background images would be retrieved. The similarity is calculated based on colour histograms in the HSV colour space. A more detailed explanation can be found here.

因为我希望用户可以选择一系列图像,所以我编写了一个Python脚本,用作图像搜索引擎。 如果在用户浏览一系列可用的背景图像时选择了图像,则将检索相似外观的背景图像。 基于HSV颜色空间中的颜色直方图计算相似度。 在这里可以找到更详细的解释。

Here’s the result. If a user selects this background image:

这是结果。 如果用户选择此背景图片:

Similar looking images would be retrieved:

看起来相似的图像将被检索:

第2部分-开始绘制! (Part 2 — Start drawing!)

This is the fun part! The program seeks to match whatever you’re drawing with the set of images in the database. So if you draw an image with the wings spread out versus if you draw an oval (for example) the retrieved results would be different. Additionally, because the programme is not as robust, the user would have to specify the category (for example bird or boat, or car). For this particular project, I have six categories. The drawing function is also coded in Python with openCV. Once the outline is drawn, the list of coordinates would be saved. 100 sample points (the number I used for my testing, this can vary — the more points the more accurate but the programme would take longer) was taken from this outline of the drawing.

这是有趣的部分! 该程序试图将您要绘制的内容与数据库中的图像集进行匹配。 因此,如果您绘制的图像张开了翅膀,而绘制了椭圆形(例如),则检索到的结果将有所不同。 另外,由于程序不那么健壮,因此用户必须指定类别(例如,鸟,船或汽车)。 对于这个特定的项目,我有六个类别。 绘图功能也使用openCV在Python中编码。 绘制轮廓后,将保存坐标列表。 从该图形的轮廓中获取了100个采样点(我用于测试的数字可能会有所不同-采样点越多越准确,但是程序将花费更长的时间)。

The drawing did not have to be this specific, it could be just a stickman bird figure too (or stickbird lmao)
绘图不必如此具体,它也可以只是火柴人的小鸟形象(或火柴人lmao)

第3部分-将样本点与预处理的图像描述符进行比较 (Part 3 — Comparing the sample points with pre-processed image descriptors)

Initially, I spent a very long time trying to figure out how to use image segmentation methods to get a clean cut of the target image objects so I could crop them out of their original images, figure out which one(s) matched my sketch the most, and them poisson-blend into my result image. However, this was really tricky to do and OpenCV’s image saliency techniques only worked well with certain types of images. For example,

最初,我花了很长时间试图弄清楚如何使用图像分割方法对目标图像对象进行清晰的裁剪,以便可以将其从原始图像中裁剪出来,从而找出与我的素描相匹配的图像。大多数情况下,它们都将泊松融合到我的结果图像中。 但是,这样做确实很棘手,而且OpenCV图像显着性技术仅适用于某些类型的图像。 例如,

For these images, clean masks can be obtained
对于这些图像,可以获得干净的口罩

However, if the background gets a little complicated or if the subject is not as clear, this happens:

但是,如果背景变得有点复杂或主题不太清楚,则会发生这种情况:

Hence, I decided to use the COCODataset instead.

因此,我决定改用COCODataset。

These are some of the masks of the “birds” category
这些是“鸟类”类别的一些面具

With these masks, I can use the outline of my sketch to compare against the shape context histogram descriptors of these masks. How it works can be broken down into four steps:

有了这些蒙版,我可以使用草图的轮廓与这些蒙版的形状上下文直方图描述符进行比较。 它的工作方式可以分为四个步骤:

Step 1: Finding the collection of points on shape contour

步骤1:在形状轮廓上找到点的集合

Step 2: Computing the shape context

步骤2:计算形状上下文

Step 3: Computing the cost matrix

步骤3:计算成本矩阵

Step 4: Finding the matching that minimizes total cost

步骤4:寻找可将总费用降至最低的匹配项

BY THE WAY, shape context is another fun topic to discuss that’ll take a full article by itself, so I shall not be discussing it here — but do let me know if that’ll be of interest!

顺便说一句,形状上下文是另一个有趣的话题,需要单独阅读全文,因此在这里我将不再讨论它-但请告诉我是否有兴趣!

Here’s some results:

结果如下:

So it works OKAY. The problem with the Hungarian matching algorithm is that it is extremely time costly — its O(n³)! This is also the part where I’m thinking of implementing some ML/DL techniques to speed up the process.

这样就可以了。 匈牙利匹配算法的问题在于,它非常耗时-O(n³)! 这也是我正在考虑实现某些ML / DL技术以加速该过程的部分。

第4部分-将最接近的匹配项混合到所选背景图像中 (Part 4 — Blending the closest match into the selected background image)

The last part of this project (after using the target mask to “crop” the image out) is to use poisson blending to blend the image into our initially selected background image.

该项目的最后一部分(使用目标蒙版“裁剪”出图像之后)是使用泊松混合将图像混合到我们最初选择的背景图像中。

Poisson blending is one of the gradient domain image processing methods. Pixels in the resultant image are computed by solving a Poisson equation.

泊松混合是梯度域图像处理方法之一。 通过求解泊松方程来计算结果图像中的像素。

For each of the final pixels:

对于每个最终像素:

if mask(x,y) is 0:    final(x,y) = target(x,y) else:    final(x,y) = 0    for each neighbor (nx,ny) in (x-1,y), (x+1,y), (x,y-1), (x,y+1):    final(x,y) += source(x,y) - source(nx,ny)      if mask(nx,ny) is 0:        final(x,y) += target(nx,ny)      else:        final(x,y) += final(nx,ny)

All masked pixels with a non-zero value affects each other’s final value. The matrix equation Ax=b is solved to compute everything simultaneously. The size of vectors x and b are both number of pixels in the target image — vector x is what we are solving for and contains all pixels in the final image while vector b is the guiding gradient plus the sum of all non-masked neighbour pixels in the target image. These non-masked neighbour pixels are the values of pixels at the mask boundary and the guiding gradient defines the second derivative of the final mask area. Matrix A is a sparse matrix and computes the gradient of the final image’s masked pixels.The equation for x is solved to get the final image. If the guiding gradient is zero, we are just solving a Laplace equation and the values at the mask boundary are blended smoothly across. With the gradient of the source image as the guiding gradient, the mask area takes on the appearance of the source image but is smoothly blended at the boundary.

具有非零值的所有蒙版像素都会影响彼此的最终值。 求解矩阵方程Ax = b可以同时计算所有内容。 向量x和b的大小都是目标图像中的像素数-向量x是我们要求解的图像,并且包含最终图像中的所有像素,而向量b是引导梯度加所有未遮罩的相邻像素之和在目标图像中。 这些未遮罩的相邻像素是遮罩边界处的像素值,并且引导渐变定义了最终遮罩区域的二阶导数。 矩阵A是一个稀疏矩阵,用于计算最终图像的蒙版像素的梯度。求解x的方程以获得最终图像。 如果引导坡度为零,则我们正在求解拉普拉斯方程,并且将遮罩边界处的值平滑地混合在一起。 以源图像的梯度作为引导梯度,遮罩区域具有源图像的外观,但在边界处平滑融合。

OpenCV’s seamless clone function is an implementation of the algorithm mentioned above.

OpenCV无缝克隆功能是上述算法的实现。

Some results:

一些结果:

The birds were not in the original background image — they were “blended” in
这些鸟不在原始背景图像中,而是在“

第5部分-使用预先训练的模型在图像上应用神经样式传递 (Part 5 — Applying neural style transfer on the image with pre-trained models)

I did a separate article on this here! Do check it out if interested. But in a nutshell, what it does is it takes the image above and apply some cool art style to it. There is of course a range to choose from and the range largely depends on which pre-trained neural models you use.

我在这里做了另一篇文章! 如果有兴趣,请检查一下。 简而言之,它的作用是获取上面的图像并为其应用一些酷炫的艺术风格。 当然,有一个范围可供选择,范围很大程度上取决于您使用的预训练神经模型。

Here’s some examples:

这里有一些例子:

This project is actually far from done. Mainly because the matching algorithm takes too long and the pre-processing phase requires some manual intervention still. However, most of this (save for the last part) is just mathematical image manipulation techniques! If ML/DL techniques are used, the processing phase could potentially be improved. Nonetheless, I think it is still a fun project to work on and it made me learn a lot more about image processing techniques (and math lol).

这个项目实际上还远远没有完成。 主要是因为匹配算法花费的时间太长,并且预处理阶段仍然需要一些人工干预。 但是,大多数(最后一部分除外)只是数学图像处理技术! 如果使用ML / DL技术,则可能会改善处理阶段。 尽管如此,我认为这仍然是一个有趣的项目,它使我学到了更多有关图像处理技术(和数学笑)的知识。

Anyhow, let me know if I should do a more in-depth walkthrough of each part!

无论如何,请告诉我是否应该对每个部分进行更深入的演练!

Happy OpenCV-ing! ୧(﹒︠ᴗ﹒︡)୨

OpenCV-ing祝您愉快! ୧(﹒︠ᴗ﹒︡)୨

翻译自: https://medium.com/swlh/image-creation-for-non-artists-opencv-project-walkthrough-d56ee21db5b6

opencv 创建图像


http://www.taodudu.cc/news/show-863792.html

相关文章:

  • 使用TensorFlow进行深度学习-第2部分
  • 基于bert的语义匹配_构建基于BERT的语义搜索系统…针对“星际迷航”
  • 一个数据包的旅程_如何学习数据科学并开始您的惊人旅程
  • jupyter 托管_如何在本地托管的Jupyter Notebook上进行协作
  • fitbit手表中文说明书_如何获取和分析Fitbit睡眠分数
  • 熔池 沉积_用于3D打印的AI(第2部分):异常熔池检测的一课学习
  • 机器学习 可视化_机器学习-可视化
  • 学习javascript_使用5行JavaScript进行机器学习
  • 强化学习-动态规划_强化学习-第4部分
  • 神经网络优化器的选择_神经网络:优化器选择的重要性
  • 客户细分_客户细分:K-Means聚类和A / B测试
  • 菜品三级分类_分类器的惊人替代品
  • 开关变压器绕制教程_教程:如何将变压器权重和令牌化器从AllenNLP上传到HuggingFace
  • 一般线性模型和混合线性模型_线性混合模型如何工作
  • 为什么基于数字的技术公司进行机器人研究
  • 人类视觉系统_对人类视觉系统的对抗攻击
  • 在神经网络中使用辍学:不是一个神奇的子弹
  • 线程监视器模型_为什么模型验证如此重要,它与模型监视有何不同
  • dash使用_使用Dash和SHAP构建和部署可解释的AI仪表盘
  • 面向表开发 面向服务开发_面向繁忙开发人员的计算机视觉
  • 可视化 nltk_词嵌入:具有Genism,NLTK和t-SNE可视化的Word2Vec
  • fitbit手表中文说明书_使用机器学习预测Fitbit睡眠分数
  • redis生产环境持久化_在SageMaker上安装持久性Julia环境
  • alexnet vgg_从零开始:建立著名的分类网2(AlexNet / VGG)
  • 垃圾邮件分类 python_在python中创建SMS垃圾邮件分类器
  • 脑电波之父:汉斯·贝格尔_深度学习,认识聪明的汉斯
  • PyCaret 2.0在这里-新增功能?
  • 特征选择 回归_如何执行回归问题的特征选择
  • 建立神经网络来预测贷款风险
  • redshift教程_分析和可视化Amazon Redshift数据—教程

opencv 创建图像_非艺术家的图像创建(OpenCV项目演练)相关推荐

  1. python创建数据集_使用Python从图像创建数据集以进行人脸识别

    我正在尝试用Python编写人脸识别程序(我将应用k-nn算法进行分类). 首先,我将图像转换为灰度,然后创建了一个长列向量(通过使用Opencv的imagedata函数),该向量具有图像的像素(总共 ...

  2. 响应式图像_如何为响应图像使用HTML5“图片”,“ srcset”和“大小”

    响应式图像 <picture>是HTML5元素,旨在为我们提供更多的功能和性能更好的响应图像功能. Picture标签不会加载单个图像并尝试调整其大小以适合所有可能的视口尺寸和布局,而是加 ...

  3. acdsee扫描没有图像_详解CT图像常见伪影成因及解决方法

    CT 图像伪影 (artifact) 是指重建图像上与实际解剖结构不相符的密度异常变化.CT 图像比传统平扫X线更容易出现伪影,这是因为 CT 图像是由成千上万独立的原始测量数据重建而得,而计算机重建 ...

  4. 风格化图像_【开源】图像风格化和目标检测

    团队今年两项新成果的代码现已开源,欢迎试用. 1. 任意风格图像风格化(ACM Multimedia 2020) 图像风格化方法可学习图像的内容和风格的特征表示,然后根据这些特征表示生成风格化后的图像 ...

  5. python opencv 文字识别_文本识别 使用 Tesseract 进行 OpenCV OCR 和 文本识别

    文本识别 用 Tesseract 进行 OpenCV OCR 和 文本识 在本教程中,您将学习如何应用OpenCV OCR(光学字符识别).我们将使用OpenCV,Python和Tesseract 执 ...

  6. python 批量创建线程_【Python】批量创建线程

    在<[Python]线程的创建.执行.互斥.同步.销毁>(点击打开链接)中介绍了Python中线程的使用,但是里面线程的创建,使用了很原始的方式,一行代码创建一条.其实,Python里是可 ...

  7. OpenCV读取图像_显示图像和保存图像

    配置好 OpenCV 以后,包含以下两个头文件: #include "cv.h" #include "highgui.h" IplImage* image=cv ...

  8. css 背景渐变 图像_交叉渐变背景图像

    css 背景渐变 图像 I've been working on a method to fade a page background image sequence, like the current ...

  9. 安装ubuntu 创建分区_安装Ubuntu后如何创建单独的主分区

    安装ubuntu 创建分区 Ubuntu doesn't use a separate /home partition by default, although many Linux users pr ...

最新文章

  1. 胖子哥的大数据之路(10)- 基于Hive构建数据仓库实例
  2. 【SICP练习】91 练习2.64
  3. mc pe Linux服务器,MC 基岩版(PE) 服务器来了
  4. php socket ubuntu,Ubuntu升级php7.0配置fpm socket
  5. Python_函数做字典的值
  6. 【学习笔记】《数据挖掘:理论与算法》CH4神经网络
  7. 2019年湘潭大学程序设计竞赛
  8. undo表空间暴长,如何取消自动扩展
  9. LInux线程——多线程与fork之间的问题
  10. python函数返回值_Python中函数的返回值示例浅析
  11. java高分面试指南:javamvc模式简单案例
  12. 【转】设计模式六大原则——SOLID
  13. Android系统启动流程源码分析
  14. Ubuntu通过apt安装LAMP环境
  15. HTML5前端基础知识
  16. html平安夜模板,高校社团平安夜活动策划模板
  17. 企业风险管理与内部控制常见问题与思考
  18. 微信升级外链管理规范,「砍一刀帮我加速」要被禁止了
  19. 本地计算机无法设置共享文件夹,共享服务,详细教您win10共享文件夹无法访问怎么办...
  20. 在线会议中人脸面部轮廓图像提取(三)——Dlib库人脸面部轮廓图像特征提取

热门文章

  1. 网页简单上传图片 imgareaselect插件
  2. Unix时代的开创者Ken Thompson
  3. c语言链表代码大全,C语言实现链表
  4. list python 转tensor_Tensorflow模型量化4 --pb转tflite(uint8量化)小结
  5. python操作mongodb语法_python操作mongodb怎么找到所有的集合
  6. python求1+2+3+....+100的和注意事项_python006(求1-2+3-4+5.....99的所有数的和)
  7. handler和thread之间如何传输数据_使用Mac OS X如何开启和配置防火墙
  8. 汇编烧程序进单片机要什么软件_单片机编程语言及应用技巧解析
  9. c枚举类型enum例题_SystemVerilog数据类型
  10. fastjson jar包_经过性能对比,我发现温少的FastJson真牛。