AnswerOpenCV(1001-1007)一周佳作欣赏

简介: 外国不过十一,所以利用十一假期,看看他们都在干什么。一、小白问题http://answers.opencv.org/question/199987/contour-single-blob-with-multiple-object/ Contour Single blob with multiple object Hi to everyone.
外国不过十一,所以利用十一假期,看看他们都在干什么。
一、小白问题

Contour Single blob with multiple object

Hi to everyone.

I'm developing an object shape identification application and struck up with separating close objects using contour, Since close objects are identified as single contour. Is there way to separate the objects?

Things I have tried:1. I have tried Image segmentation with distance transform and Watershed algorithm - It works for few images only2. I have tried to separate the objects manual using the distance between two points as mentioned in http://answers.opencv.org/question/71... - I struck up with choosing the points that will separate the object.

I have attached a sample contour for the reference.

image description

Please suggest any comments to separate the objects.

分析:这个问题其实在阈值处理之前就出现了,我们常见的想法是对图像进行预处理,比如HSV 分割,或者在阈值处理的时候想一些方法。


二、性能优化
http://answers.opencv.org/question/109754/optimizing-splitmerge-for-clahe/

Optimizing split/merge for clahe

I am trying to squeeze the last ms from a tracking loop. One of the time consuminig parts is doing adaptive contrast enhancement (clahe), which is a necessary part. The results are great, but I am wondering whether I could avoid some copying/splitting/merge or apply other optimizations.

Basically I do the following in tight loop:

cv::cvtColor(rgb, hsv, cv::COLOR_BGR2HSV);
 
std::vector<cv::Mat> hsvChannels;
 
cv::split(hsv, hsvChannels);
 
m_clahe->apply(hsvChannels[2], hsvChannels[2]); /* m_clahe constructed outside loop */
 
cv::merge(hsvChannels, hsvOut);
 
cv::cvtColor(hsvOut, rgbOut, cv::COLOR_HSV2BGR);

On the test machine, the above snippet takes about 8ms (on 1Mpix images), The actual clahe part takes only 1-2 ms.

1 answer

You can save quite a bit. First, get rid of the vector. Then, outside the loop, create a Mat for the V channel only.

Then use extractChannel and insertChannel to access the channel you're using. It only accesses the one channel, instead of all three like split does.

The reason you put the Mat outside the loop is to avoid reallocating it every pass through the loop. Right now you're allocating and deallocating three Mats every pass.

test code:

#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>
 
using namespace std;
using namespace cv;
 
int main(){
 
TickMeter tm;
Ptr<CLAHE> clahe = createCLAHE();
    clahe->setClipLimit(4);
    vector <Mat> hsvChannels;
    Mat img, hsv1, hsv2, hsvChannels2, diff;
    img = imread("lena.jpg");
    cvtColor (img, hsv1, COLOR_BGR2HSV);
    cvtColor (img, hsv2, COLOR_BGR2HSV);
    tm.start();
for (int i = 0; i < 1000; i++)
{
        split(hsv2, hsvChannels);
        clahe->apply(hsvChannels[2], hsvChannels[2]);
        merge(hsvChannels, hsv2);
}
    tm.stop();
    cout<< tm << endl;
    tm.reset();
    tm.start();
 
for (int i = 0; i < 1000; i++) 
{
        extractChannel(hsv1, hsvChannels2, 2);
        clahe->apply(hsvChannels2, hsvChannels2);
        insertChannel(hsvChannels2, hsv1, 2);
}
    tm.stop();
    cout<< tm;
    absdiff(hsv1, hsv2, diff);
    imshow("diff", diff*255);
    waitKey();
}

我运行这段代码的结果为:
4.63716sec
3.80283sec
应该说其中关键的一句就是使用:
extractChannel(hsv1, hsvChannels2, 2);
代替
split(hsv2, hsvChannels);
能够单句提高1MS左右时间,而这种费时的方法是我目前经常采用的,应该说这题很有较益。

三、基本算法

Compare two images and highlight the difference

Hi - First I'm a total n00b so please be kind. I'd like to create a target shooting app that allows me to us the camera on my android device to see where I hit the target from shot to shot. The device will be stationary with very little to no movement. My thinking is that I'd access the camera and zoom as needed on the target. Once ready I'd hit a button that would start taking pictures every x seconds. Each picture would be compared to the previous one to see if there was a change - the change being I hit the target. If a change was detected the two imaged would be saved, the device would stop taking picture, the image with the change would be displayed on the device and the spot of change would be highlighted. When I was ready for the next shot, I would hit a button on the device and the process would start over. If I was done shooting, there would be a button to stop.

Any help in getting this project off the ground would be greatly appreciated.

retag flag offensive

This will be a very basic algorithm just to evaluate your use case. It can be improved a lot.

(i) In your case, the first step is to identify whether there is a change or not between 2 frames. It can be identified by using a simple StandardDeviation measurement. Set a threshold for acceptable difference in deviation.

Mat prevFrame, currentFrame;

for(;;)
{
    //Getting a frame from the video capture device.
    cap >> currentFrame;

    if( prevFrame.data )
    {
         //Finding the standard deviations of current and previous frame.
         Scalar prevStdDev, currentStdDev;
         meanStdDev(prevFrame, Scalar(), prevStdDev);
         meanStdDev(currentFrame, Scalar(), currentStdDev);

          //Decision Making.
          if(abs(currentStdDev - prevStdDev) < ACCEPTED_DEVIATION)
          {
               Save the images and break out of the loop.
          }     
    }

    //To exit from the loop, if there is a keypress event.
    if(waitKey(30)>=0)
        break;

    //For swapping the previous and current frame.
    swap(prevFrame, currentFrame);
}

(ii) The first step will only identify the change in frames. In order to locate the position where the change occured, find the difference between the two saved frames using AbsDiff. Using this difference image mask, find the contours and finally mark the region with a bounding rectangle.

Hope this answers your question.

flag offensive link

这道题难道不是对absdiff的应用吗?直接absdiff,然后阈值,数数就可以了。

四、系统配置

opencv OCRTesseract::create v3.05

I have the version of tesseract 3.05 and opencv3.2 installed and tested. But when I tried the end-to-end-recognition demo code, I discovered that tesseract was not found using OCRTesseract::create and checked the documentation to find that the interface is for v3.02. Is it possible to use it with Tesseract v3.05 ? How?

retag flag offensive

How to create OpenCV binary files from source with tesseract ( Windows )

image description

i tried to explain the steps

Step 1.download https://github.com/DanBloomberg/lepto...

extract it in a dir like "E:/leptonica-1.74.4"

run cmake

where is the source code : E:/leptonica-1.74.4

where to build binaries : E:/leptonica-1.74.4/build

click Configure buttonselect compiler

see "Configuring done"click Generate button and see "Generating done"

image description

Open Visual Studio 2015 >> file >> open "E:\leptonica-1.74.4\build\ALL_BUILD.vcxproj"select release, build ALL BUILD

see "Build: 3 succeeded" and be sure E:\leptonica-master\build\src\Release\leptonica-1.74.4.lib and E:\leptonica-1.74.4\build\bin\Release\leptonica-1.74.4.dll have been createdimage description


Step 2.download https://github.com/tesseract-ocr/tess...

extract it in a dir like "E:/tesseract-3.05.01"

create a directory E:\tesseract-3.05.01\Files\leptonica\include

copy *.h from E:\leptonica-master\src into E:\tesseract-3.05.01\Files\leptonica\includecopy *.h from E:\leptonica-master\build\src into E:\tesseract-3.05.01\Files\leptonica\include

run cmake

where is the source code : E:/tesseract-3.05.01

where to build binaries : E:/tesseract-3.05.01/build

click Configure buttonselect compiler

set Leptonica_DIR to E:/leptonica-1.74.4\buildclick Configure button againsee "Configuring done"click Generate button and see "Generating done"

Open Visual Studio 2015 >> file >> open "E:/tesseract-3.05.01\build\ALL_BUILD.vcxproj"build ALL_BUILD

be sure E:\tesseract-3.05.01\build\Release\tesseract305.lib and E:\tesseract-3.05.01\build\bin\Release\tesseract305.dll generated


Step 3.create directory E:\tesseract-3.05.01\include\tesseract

copy all *.h files from

E:\tesseract-3.05.01\api

E:\tesseract-3.05.01\ccmain

E:\tesseract-3.05.01\ccutil

E:\tesseract-3.05.01\ccstruct

to E:/tesseract-3.05.01/include\tesseract

in OpenCV cmake set Tesseract_INCLUDE_DIR : E:/tesseract-3.05.01/include

set tesseract_LIBRARY E:/tesseract-3.05.01/build/Release/tesseract305.lib

set Lept_LIBRARY E:/leptonica-master/build/src/Release/leptonica-1.74.4.lib

when you click Configure button you will see "Tesseract: YES" it means everything is OK

make other settings and generate. Compile ....

flag offensive link
禾路按语:OCR问题,一直都是图像处理的经典问题。那么tesseract是这个方向的非常经典的项目,包括east一起进行结合研究。

五、算法问题

Pyramid Blending with Single input and Non-Vertical Boundar

Hi All,

Here is the input image.image description

Say you do not have the other half of the images. Is it still possible to do with Laplacian pyramid blending?

I tried stuffing the image directly into the algorithm. I put weights as opposite triangles. The result comes out the same as the input.My another guess is splitting the triangles. Do gaussian and Laplacian pyramid on each separately, and then merge them.

But the challenge is how do we apply Laplacian matrix on triangular data. What do we fill on the missing half? I tried 0. It made the boundary very bright.

If pyramid blending is not the best approach for this. What other methods do you recommend me to look into for blending?

Any help is much appreciated!

retag flag offensive

Comments

the answer is YES.what you need is pyrdown the images and lineblend them at each pyramid

jsxyhelu gravatar image jsxyhelu  (26 hours ago) edit

Thank you for your comment. I tried doing that (explained by my 2nd paragraph). The output is the same as the original image. Please note where I want to merge is NOT vertical. So I do not get what you meant by "line blend".

这个问题需要实现的是mulitband blend,而且实现的是倾斜过来的融合,应该说很奇怪,不知道在什么环境下会有这样的需求,但是如果作为算法问题来说的话,还是很有价值的。首先需要解决的是倾斜的line bend,值得思考。

六、新玩意

DroidCam with OpenCV

With my previous laptop (Windows7) I was connecting to my phone camera via DroidCam and using videoCapture in OpenCV with Visual Studio, and there was no problem. But now I have a laptop with Windows 10, and when I connect the same way it shows orange screen all the time. Actually DroidCam app in my laptop works fine, it shows the video. However while using OpenCV videoCapture from Visual Studio it shows orange screen.

Thanks in advance

retag flag offensive
Disable laptop webcam from device manager and then restart. Then it works

七、算法研究

OpenCV / C++ - Filling holes

Hello there,

For a personnel projet, I'm trying to detect object and there shadow. These are the result I have for now:Original: 

15384708243910086.pngimg_7d453d0dc5fbb403bd5f3afcf13d5fbf.jpe

Object: 

Shadow: 

The external contours of the object are quite good, but as you can see, my object is not full.Same for the shadow.I would like to get full contours, filled, for the object and its shadow, and I don't know how to get better than this (I juste use "dilate" for the moment).Does someone knows a way to obtain a better result please?Regards.

有趣的问题,研究看看。



 


  





目前方向:图像拼接融合、图像识别 联系方式:jsxyhelu@foxmail.com
目录
相关文章
|
3月前
|
人工智能 运维 程序员
阿里云千问办公、Qoder Teams、Qoder CN区别与选择指南:模型能力、适用场景与最新活动参考
阿里云2026年推出三款AI办公工具:千问办公(QwenWork)面向非技术岗,主打PPT/Excel/公文自动化;Qoder CN为开发者个人版,强调合规私有化编码;Qoder Teams则是企业级研发管理平台,支持团队权限、知识沉淀与内网部署。选型需按角色精准匹配。
799 0
|
4月前
|
人工智能 运维 安全
Qoder CN完整测评:自主任务引擎、多角色协同、命令行工具与选型参考
软件研发业务持续朝着复杂化、高速迭代的方向演进,传统纯人工开发模式的短板不断凸显。手写大量重复代码消耗研发精力,程序漏洞难以完全规避,多人协作环境之下团队代码规范很难统一,大型多模块工程项目落地周期漫长。设计、编码、测试、运维各个岗位相互割裂,大量机械性重复工作持续挤占研发人员处理核心业务的时间。在此行业背景下,具备任务自主规划、多角色协同、持续自我进化能力的AI研发智能体,成为个人开发者、中小研发小组以及大型企业技术部门的刚需。
406 0
|
6月前
|
人工智能 程序员 API
别再盲目卷Skills了!大模型时代的工具调用(Tool-Use),正在迎来底层范式革命
本文深度剖析Skills(技能包)的本质:当前人工硬编码的Skills只是弥补大模型执行力不足的过渡性“补丁”,而非Agent终局方案。文章指出其三大痛点——幻觉调用、上下文过载、缺乏自适应,并前瞻性提出四大演进路径:自主习得技能、GUI/OS级原生操作、MCP协议标准化、推理与执行架构融合,揭示Skills将从“人工编写”迈向“智能体自主进化”的必然趋势。
732 0
别再盲目卷Skills了!大模型时代的工具调用(Tool-Use),正在迎来底层范式革命
|
5月前
|
缓存 人工智能 安全
GPT-5.6 Terra与GPT-5.5全维度实测:定价、性能、迁移A/B方案完整解析
2026年OpenAI正式发布GPT-5.6系列全量模型,包含旗舰Sol、均衡Terra、轻量Luna三大层级,其中GPT-5.6 Terra作为替代前代GPT-5.5的主力均衡模型,凭借全套计费标准统一减半的核心优势,成为批量编码、长上下文重构、企业日常AI工作流的热门选择。Terra与GPT-5.5共享完全一致的上下文容量、最大输出长度与API兼容协议,迁移仅需替换一行模型标识字符串,但存在关键短板:官方未单独公布Terra编码专项基准分数,仅放出定性成本对比描述,无法直接确认其代码生成、复杂补丁修复能力是否持平GPT-5.5。本文结合官方定价数据、多套行业基准、不同量级业务成本测算、标准
927 0
|
12月前
|
JSON 缓存 Java
Spring Boot集成 Swagger2 展现在线接口文档
Swagger是一款用于生成和管理API文档的开源工具,解决前后端分离架构中接口文档滞后问题。通过集成Swagger2,可自动生成实时在线文档,并支持在线测试接口,提升开发效率。本文详解Spring Boot中集成Swagger2的配置与常用注解,如@Api、@ApiOperation等,实现接口文档自动化,便于团队协作与维护。
|
7月前
|
人工智能 JSON 自然语言处理
大模型应用:贝叶斯推理赋能大模型:构建带置信度的可信智能问答系统.108
本文提出“大模型+贝叶斯推理”协同方案,直击大模型幻觉痛点:让大模型专注语言理解与生成,贝叶斯模块基于先验知识与用户证据(如症状)动态计算各结论的置信概率,输出“结论+概率+依据”,显著提升医疗、法律等高可信场景的可靠性与可解释性。
402 5
|
8月前
|
NoSQL 数据可视化 网络安全
redis做数据备份和恢复的常用方法
推荐使用可视化Redis客户端yunedit-redis进行跨机房备份与恢复:支持全库/单DB/正则导出,ZIP包直导直入;可灵活指定目标DB,适配多实例迁移;内置SSH隧道,轻松穿透云内网。操作简便,无需两端部署工具。
|
7月前
|
弹性计算 监控 网络协议
服务器部署后用户反馈访问慢,一份 SRE 视角的全链路网络诊断实战清单
本文总结后端/运维/站长高频遇到的“用户访问异常”问题,提出可落地的“全链路诊断七步法”:从多地Ping、TCPing、HTTP分段测速、Traceroute定位拥塞点,到DNS一致性检查与IP信誉扫描。不讲理论,只教命令、工具和典型现象判断,助你快速定位网络瓶颈,告别“本地正常、用户炸锅”的排查困境。
933 0
|
9月前
|
缓存 监控 Java
从 GC 频繁到毫秒级停顿:JVM 内存调优分代配比、晋升机制与架构策略全拆解
本文深入剖析JDK 17下JVM内存调优核心:从分代回收底层逻辑、年轻代/老年代配比规则,到对象晋升机制与四大坑点;涵盖G1/Parallel收集器调优实践、代码/架构级优化策略,并附生产级参数配置与避坑指南,兼顾深度与落地性。
723 3
|
自然语言处理 数据挖掘 BI
阿里云瑶池 Data Agent 体验馆上线啦
阿里云瑶池 Data Agent 体验馆上线啦,通过自然语言描述需求,Agent 自动完成需求解析、数据理解与洞察挖掘,快速生成定制报告,大幅减少人工操作,提升分析效率与决策深度。
1061 96

热门文章

最新文章