OpenCV

opencv 单通道合并为多通道

霸气de小男生 提交于 2021-02-02 05:30:29
int main(){ cv::Mat m1 =(cv::Mat_< int >( 3 , 2 )<< 1 , 2 , 3 , 4 , 5 , 6 ); cv::Mat m2 =(cv::Mat_< int >( 3 , 2 )<< 2 , 4 , 6 , 8 , 10 , 12 ); cv::Mat m3 =(cv::Mat_< int >( 3 , 2 )<< 3 , 6 , 9 , 12 , 15 , 18 ); cv::Mat inm[] = {m1,m2,m3}; cv::Mat outm; cv::merge(inm, 3 ,outm); // 合并后行数和列数不变。each element of the output array will be a concatenation of the elements of // the input arrays, where elements of i-th input array are treated as mv[i].channels()-element vectors. std::cout<<outm<< std::endl; std::vector <cv::Mat> inm1; inm1.push_back(m1); inm1.push_back(m2); inm1.push_back(m3); cv::Mat

opencv教程--ubuntu下安装

风流意气都作罢 提交于 2021-01-31 09:08:23
安装前需要保证以下文件正确安装: gcc 4.4.x 或更高版本。sudo apt-get install build-essential(这个包中包含g++,gcc等) cmake 2.6 或更高版本。sudo apt-get install cmake gtk+ 2.x 或更高版本,这个必须包含头(sudo apt-get isntall libgtk2.0-dev) pkgconfig ----sudo apt-get install pkgconfig python 2.6 或更高版本。这个ubuntu 12.04以及12.10都已经安装,可以不用安装了。 一般来说,这么多就够了。 至于安装包,可以通过google找到官方网站直接下载,也可以通过git。我使用的是OpenCV-2.4.3.tar.bz2,下好后解压:tar -jxvf OpenCV-2.4.3.tar.bz2。接下来开始编译、安装了 进入文件夹。cd OpenCV-2.4.3 使用cmake构建makefile文件。cmake . 你可以仔细看看有没有缺什么。 使用make编译。make 安装,这个需要root权限。sudo make install。 这样可能出现头文件包含问题,你最好把opencv 的 include文件复制到/usr/include。 接下来我们来先写个例子吧(显示图像):

Ubuntu安装多个版本的Opencv

本秂侑毒 提交于 2021-01-31 08:32:09
参考: https://www.cnblogs.com/hxzkh/p/8473190.html 将该博主的某一部分摘录出来 ->lsdslam 中的opencv版本 3、编译 opencv 由于这个代码用到了opencv2.4 版本,所以我们要下载对版本。之前一直编译不同,以为是下载的版本有问题,我下载了 2.4.9、2.4.13、2.4.13.5,最后用 2.4.13版本跑通了,当然我不是说 2.4.9、2.4.13.5 等其他 2.4 版本不能跑通。为什么这么说呢?因为我之前之所以出问题编译出错是因为我之前装了 3.1.0的版本,所以不行。所以,你可以试一试,我觉得只要是 2.4. 的版本应该都可以。 这里我简单交代一下我曲折的编译之路。。。然后再给出正确方法。 首先说一下 opencv 版本的问题,之前跑另一个程序需要opencv3,,那时候没玩过这,也不懂,就按默认路径安装了 opencv3.1.0,然后它自己就装到了 usr/local/include、usr/local/lib,还有share什么的,好多个文件夹,导致我卸载都很麻烦,要卸载它,你就得手动删掉它所有安装的路径下的相关文件,这些安装信息在安装时保存在了一个什么 install 文件中,具体我忘了(反正我是运行 unintall 不行,所以才手动一个一个删的)。 就这样,删掉了opencv3.1.0版本

PyTorch OCR模型的安卓端部署

风格不统一 提交于 2021-01-30 05:53:25
开发环境选择 本文操作系统为Windows,因为Windows上的安卓模拟器选择较多,并且真机调试也比较方便; 交叉编译在Windows和Ubuntu上都进行了尝试,都可行,但是如果是Ubuntu上交叉编译之后再挪到Windows的话,容易出幺蛾子; 我目前使用的最稳定的工具版本组合是:ndk18、androidstudio4.1、cmake3.10、gradle6.5、MinGW(CodeBlocks自带)。 1. PyTorch模型转NCNN 这一小节是介绍如何将自己重新训练过的PyTorch模型转成ncnn,如果没有重训练需求的话,可以直接跳过这一节。 (1) 整体步骤 理想情况下,从PyTorch转到ncnn只需要下面两步: PyTorch转ONNX torch.onnx._export(model, x, path, opset_version=11) ONNX转NCNN ./onnx2ncnn model.onnx model.param model.bin 遇到问题的适合解决思路如下: convert.png 下面介绍一下我在做ChineseOCRLite中的PSENet模型转换的过程中遇到的问题。 (2)实际操作的时候可能会遇到各种问题 问题1:ReLU6不支持 概述:ReLU6算子在转换的时候容易出现不支持的情况,需要使用其他算子替代 解决:使用torch

Find Rotated Rectangle in OpenCV Python

孤人 提交于 2021-01-29 20:22:09
问题 i have python function like below def getContours(img, imgContour): contours, hierarchy = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)[-2:] for cnt in contours: area = cv2.contourArea(cnt) if area > 1000: cv2.drawContours(imgContour, contours, -1, (255, 0, 255), 7) peri = cv2.arcLength(cnt, True) approx = cv2.approxPolyDP(cnt, 0.02 * peri, True) # print(len(approx)) x, y, w, h = cv2.boundingRect(approx) #cv2.rectangle(imgContour, (x, y), (x + w, y + h), (0, 255, 0), 5) if len

pytesseract not recognizing text as expected?

99封情书 提交于 2021-01-29 20:16:53
问题 I am trying to run a simple license plate image through opencv and pytesseract to get the text but I am having trouble getting anything out of it. Following the tutorial here: https://circuitdigest.com/microcontroller-projects/license-plate-recognition-using-raspberry-pi-and-opencv I'm running on a macbook with everything installed in anaconda and no errors as far as I see, but when I run my code I get the cropped image but no detected number: (computer_vision) mac@x86_64-apple-darwin13 lpr %

how to record screen in high quality

痴心易碎 提交于 2021-01-29 19:11:35
问题 i am creating a screen recorder for desktop in python. and i have already completed the coding part but when i record the screen why it is not recording in high defination. problem......... 1> i want to record the screen in high quality what should i do. 2> i am also trying to capute my cursor with the help on cv2.circle() but i want to create the circle with less opacity or more transparent my code import cv2 import numpy as np import pyautogui import datetime import win32api date=datetime

No module named 'cv2' error in new environment

坚强是说给别人听的谎言 提交于 2021-01-29 19:11:25
问题 I have tried to rectify this issue by using pip install opencv-python pip install opencv-contrib-python pip uninstall panda pip install panda conda install opencv-python Some info is that im currently using python 3.6.10 and Windows 10. opencv-python 4.2.0.32 numpy 1.18.1 panda 0.3.1 tensorflow-gpu 1.14.0 I created a new env but cant seem to import cv2 over on Jupyter Notebook. My earlier environment was able to do so. When i tried to pip install the opencv-python==4.1.2.30 (from the old

/usr/bin/ld: cannot find -lopencv_nonfree

主宰稳场 提交于 2021-01-29 18:50:54
问题 I installed OpenCV 4.1 on Ubuntu 18.04 LTS. The problem is when I compile my project's CMake file, the output is: /usr/bin/ld: cannot find -lopencv_nonfree collect2: error: ld returned 1 exit status CMakeFiles/river_flow_velocity_estimation.dir/build.make:274: recipe for target 'river_flow_velocity_estimation' failed make[2]: *** [river_flow_velocity_estimation] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/river_flow_velocity_estimation.dir/all' failed make[1]: ***

OpenCV - How to apply Kmeans on a grayscale image?

a 夏天 提交于 2021-01-29 18:37:40
问题 I am trying to cluster a grayscale image using Kmeans. First, I have a question: Is Kmeans the best way to cluster a Mat or are there newer more efficient approaches? Second, when I try this: Mat degrees = imread("an image" , IMREAD_GRAYSCALE); const unsigned int singleLineSize = degrees.rows * degrees.cols; Mat data = degrees.reshape(1, singleLineSize); data.convertTo(data, CV_32F); std::vector<int> labels; cv::Mat1f colors; cv::kmeans(data, 3, labels, cv::TermCriteria(cv::TermCriteria::EPS