Hi. I trying to detect circle only on real-time webcam video and trying to draw circle border on my targeted circle, but right now I can draw a circle on output on a random target, please help me to get the circle target. I'm developing this work in javascript and using opencv.js.
function processVideo() {
try {
if (!streaming) {
// clean and stop.
src.delete();
dst.delete();
dstC1.delete();
dstC3.delete();
return;
}
let begin = Date.now();
// start processing.
cap.read(src);
cv.cvtColor(src, dst, cv.COLOR_RGBA2GRAY);
cv.blur(dst, dstC1, ksize, anchor, cv.BORDER_DEFAULT); // blur the image to avoids noise
cv.Canny(dstC1, dstC1, 50, 100, 3, false); // black and white border
let contours = new cv.MatVector();
let hierarchy = new cv.Mat();
cv.findContours(dstC1, contours, hierarchy, cv.RETR_CCOMP, cv.CHAIN_APPROX_SIMPLE, offset = new cv.Point(0, 0));
let cnt = contours.get(0);
let contoursColor = new cv.Scalar(255, 255, 255);
let circleColor = new cv.Scalar(255, 0, 0);
let circle = cv.minEnclosingCircle(cnt);// this one for circle
cv.drawContours(dstC1, contours, 0, contoursColor, 1, 8, hierarchy, 100);
for (let i = 0; i < 4; i++) {
cv.circle(dstC1, circle.center, circle.radius, circleColor, 3);
}
cv.imshow('canvasOutput', dstC1);
let delay = 1000/FPS - (Date.now() - begin);
setTimeout(processVideo, delay);
} catch (err) {
utils.printError(err);
}
};
please help me to detect circle only.
Thank you.
↧
Im trying to detect circle only at real-time webcam, and draw circle on it.
↧
How can I use Hu moments in java?
Hi. I want to extract feature from the image using the hu moments function. But I didn't find any examples of this in java. How do I do the calculation for hu moments in Java?
↧
↧
How to pass the cv::Mat or cv::cuda::GpuMat to custom CUDA kernel?
Is there an efficient way to pass the Mat to CUDA custom kernel? Can someone please help me with an example?
Thanks a million,
Hua
↧
Remove the black line surrounding text in opencv
I am trying to remove the black lines surrounding the text if present any. My purpose is to just have enough portion of the image to extract each character in it. The additional black lines are noise when i am trying to extract characters.
I have tried using floodfill in opencv but the image contains some white pixels before the black line starts in the upper left corner. So it hasn't been fruitful. I tried cropping by means of finding contours but even that does not work.
This is the original image

import cv2
import numpy as np
img = cv2.imread('./Cropped/22.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
_,thresh = cv2.threshold(gray,1,255,cv2.THRESH_BINARY)
contours,hierarchy = cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
cnt = contours[0]
x,y,w,h = cv2.boundingRect(cnt)
crop = img[y:y+h,x:x+w]
cv2.imshow('Image',img)
cv2.imshow('Cropped Image',crop)
cv2.waitKey(0)
and using floodfill
img = cv2.imread('./Cropped/22.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# threshold the gray image to binarize, and negate it
gray = cv2.bitwise_not(gray)
bw = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, \
cv2.THRESH_BINARY, 15, -2)
# find external contours of all shapes
contours,h = cv2.findContours(bw, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
# create a mask for floodfill function, see documentation
h,w,_ = img.shape
mask = np.zeros((h+2,w+2), np.uint8)
# determine which contour belongs to a square or rectangle
for cnt in contours:
poly = cv2.approxPolyDP(cnt, 0.02*cv2.arcLength(cnt,True),True)
if len(poly) == 4:
# if the contour has 4 vertices then floodfill that contour with black color
cnt = np.vstack(cnt).squeeze()
_,binary,_,_ = cv2.floodFill(bw, mask, tuple(cnt[0]), 0)
# convert image back to original color
binary = cv2.bitwise_not(binary)
cv2.imshow('Image', binary)
cv2.waitKey(0)
cv2.destroyAllWindows()
results in the two cases are as follows

But there appears to be no change.
And this using floodfill
.
which does not remove any borders.
If any can please help out,it will be really great.
↧
How to make fft convolution in OpenCV?
I have Matlab code for convolution in Fourier Transform but I don't know how to implement that in OpenCV. Please help me, I don't have time to read through the documents and testing it is work or not.
fftImg = fft2(I_double);
fft_gaussianKernel = fft2(Gauss_1, size(Ir, 1), size(Ir, 2); // Gauss_1 is the gaussian kernel the same size as the image.
fgauss = fftshift(fgauss);
Output = ifft2(fgauss .* fftImg); // inverse fourier transform
I hope someone can provide me the example code.
Best regards,
Hua
Best regards,
Hua
↧
↧
Replace subsection of Mat with another Mat.
I have an image stored in a Mat object (BigImage).
I also have a smaller Mat image that fits inside the bounds of first mat object (SmallImage).
Currently I'm replacing a section of BigImage with SmallImage.
I'm doing this by iterating and doing a pixel by pixel assignment from SmallImage to BigImage.
Is there a faster way of doing thing?
↧
Trying to read a csv with read_csv to load features of a CNN in a matrix
I am trying to train an SVM set by loading a matrix of features extracted from a CNN using CvMLData and reading the .cvs file to load it, but when I try to load.cvs the program shows an error: :
msg="C:\\opencv2412\\sources\\modules\\core\\src\\datastructs.cpp:426: error: (-211) **Storage block size is too small to fit the sequence elements in function cvSetSeqBlockSize**\n" ...
The.cvs file has the following format : 0.615685, 0.647057, 0.682354, 0.713726, 0.737255...
My.csv is 1.9 GB : (
Is there any solution for this problem?
↧
Pan Tilt Zoom
Is there an inbuilt way in opencv of controlling the pan , tilt , zoom of a connected webcam . I am using a Logitech PTZ camera . Reply asap . Thanks a lot .
↧
How to make fft convolution in OpenCV?
I have Matlab code for convolution in Fourier Transform but I don't know how to implement that in OpenCV. Please help me, I don't have time to read through the documents and testing it is work or not.
fftImg = fft2(I_double);
fft_gaussianKernel = fft2(Gauss_1, size(Ir, 1), size(Ir, 2); // Gauss_1 is the gaussian kernel the same size as the image.
fgauss = fftshift(fgauss);
Output = ifft2(fgauss .* fftImg); // inverse fourier transform
I hope someone can provide me the example code.
Best regards,
Hua
Best regards,
Hua
↧
↧
can't open URL video source with opencv-python cv2.VideoCapture()
I'm using a 3rd party python app which uses the opencv-python module to retrieve mp4 video and do object detection. However when I try to run this on my local fedora 28 desktop, I am unable to retrieve any video using a URL. The extracted code is basically like so;
import cv2
import numpy as np
import re
print(cv2.getBuildInformation())
url = "https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/720/Big_Buck_Bunny_720_10s_10MB.mp4"
vid = cv2.VideoCapture(url)
if not vid.isOpened():
print("not opened")
quit()
always returned "not opened".
However if I download the file, I can open it:
import re
import requests
resp = requests.get(url)
print("url is {}".format(url))
if resp.status_code == 200:
with open('Big_Buck_Bunny_720_10s_10MB.mp4', 'wb') as f:
f.write(resp.content)
vid = cv2.VideoCapture('Big_Buck_Bunny_720_10s_10MB.mp4')
if not vid.isOpened():
print("not opened")
else:
print(vid.get(cv2.CAP_PROP_FRAME_COUNT))
returns:
url is https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/720/Big_Buck_Bunny_720_10s_10MB.mp4
frames in video are 300.0
The buildinformation returns this:
General configuration for OpenCV 4.1.0 =====================================
Version control: 4.1.0
Platform:
Timestamp: 2019-04-11T16:10:20Z
Host: Linux 4.4.0-101-generic x86_64
CMake: 3.9.0
CMake generator: Unix Makefiles
CMake build tool: /usr/bin/gmake
Configuration: Release
CPU/HW features:
Baseline: SSE SSE2 SSE3
requested: SSE3
Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2
requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
SSE4_1 (13 files): + SSSE3 SSE4_1
SSE4_2 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2
FP16 (0 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
AVX (4 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
AVX2 (27 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
C/C++:
Built as dynamic libs?: NO
C++ Compiler: /usr/lib/ccache/compilers/c++ (ver 4.8.2)
C++ flags (Release): -Wl,-strip-all -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-comment -Wno-missing-field-initializers -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
C++ flags (Debug): -Wl,-strip-all -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-comment -Wno-missing-field-initializers -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
C Compiler: /usr/lib/ccache/compilers/cc
C flags (Release): -Wl,-strip-all -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wuninitialized -Winit-self -Wno-comment -Wno-missing-field-initializers -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
C flags (Debug): -Wl,-strip-all -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wuninitialized -Winit-self -Wno-comment -Wno-missing-field-initializers -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release): -L/root/ffmpeg_build/lib -Wl,--gc-sections
Linker flags (Debug): -L/root/ffmpeg_build/lib -Wl,--gc-sections
ccache: YES
Precompiled headers: NO
Extra dependencies: ade /opt/Qt4.8.7/lib/libQtGui.so /opt/Qt4.8.7/lib/libQtTest.so /opt/Qt4.8.7/lib/libQtCore.so /lib64/libz.so /opt/libjpeg-turbo/lib64/libjpeg.a dl m pthread rt
3rdparty dependencies: ittnotify libprotobuf libwebp libpng libtiff libjasper IlmImf quirc
OpenCV modules:
To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo python3 stitching video videoio
Disabled: world
Disabled by dependency: -
Unavailable: java js python2 ts
Applications: -
Documentation: NO
Non-free algorithms: NO
GUI:
QT: YES (ver 4.8.7 EDITION = OpenSource)
QT OpenGL support: NO
GTK+: NO
VTK support: NO
Media I/O:
ZLib: /lib64/libz.so (ver 1.2.3)
JPEG: /opt/libjpeg-turbo/lib64/libjpeg.a (ver 62)
WEBP: build (ver encoder: 0x020e)
PNG: build (ver 1.6.36)
TIFF: build (ver 42 - 4.0.10)
JPEG 2000: build (ver 1.900.1)
OpenEXR: build (ver 1.7.1)
HDR: YES
SUNRASTER: YES
PXM: YES
PFM: YES
Video I/O:
DC1394: NO
FFMPEG: YES
avcodec: YES (58.47.106)
avformat: YES (58.26.101)
avutil: YES (56.26.100)
swscale: YES (5.4.100)
avresample: NO
GStreamer: NO
v4l/v4l2: YES (linux/videodev2.h)
Parallel framework: pthreads
Trace: YES (with Intel ITT)
Other third-party libraries:
Lapack: NO
Eigen: NO
Custom HAL: NO
Protobuf: build (3.5.1)
OpenCL: YES (no extra features)
Include path: /io/opencv/3rdparty/include/opencl/1.2
Link libraries: Dynamic load
Python 3:
Interpreter: /opt/python/cp36-cp36m/bin/python (ver 3.6.8)
Libraries: libpython3.6m.a (ver 3.6.8)
numpy: /opt/python/cp36-cp36m/lib/python3.6/site-packages/numpy/core/include (ver 1.11.3)
install path: python
Python (for build): /opt/python/cp36-cp36m/bin/python
Java:
ant: NO
JNI: NO
Java wrappers: NO
Java tests: NO
Install to: /io/_skbuild/linux-x86_64-3.6/cmake-install
-----------------------------------------------------------------
am I missing something that would allow retrieving Videos by URL?
↧
Opencv java how to sort a bubble sheet TopLeftToBottomRight
I want to run this code but i have an error : double[] can not be converted to Point. Errors occur on e1.get(0,0 ) and e2.get(0,0 ) i need help please
public static void sortTopLeft2BottomRight(List points){
// top-left to right-bottom sort
Collections.sort(points, (e1, e2) -> {
**Point o1 = new Point(e1.get(0, 0));
Point o2 = new Point(e2.get(0, 0));**
return o1.y > o2.y ? 1 : -1;
});
}
↧
Does the Fourier Transform images have 3 channels like RGB/HSV
In RGB we have 3 channels the RED channel, GREEN channel and the BLUE channel. Does this apply to fourier transform images ? Fourier transform has three significant values that capture all the information of the sinusoidal image,
1) Spatial Frequency
2)Magnitude
3)Phase
Are these 3 like the channels in the RGB/HSV?
↧
Assertion failed (inputs.size()) in cv::dnn::dnn::Layer::getMemoryShapes, file opencv\modules\dnn\src\dnn.cpp, line 3616
So I'm getting this error when reading an ONNX model with readNetFromONNX:
> OpenCV(4.1.0) Error: Assertion failed
> (inputs.size()) in
> cv::dnn::dnn4_v20190122::Layer::getMemoryShapes,
> file
> c:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\dnn.cpp,
> line 3616
1 model loads successfully, but this particular one also gives issues in other ways, like with converting the ONNX model to Tensorflow I get this:
> ValueError: Tensor conversion
> requested dtype float32 for Tensor
> with dtype int64: 'Tensor("Mul_3:0",
> shape=(), dtype=int64)'
But I'm not sure if this has anything to do with it, also have no idea if the error is due to how I setup the model inside PyTorch or if it's in OpenCV (but the model loads and does inference fine in PyTorch itself)
Here is the standalone project:
https://github.com/Aeroxander/decodererror
Just unzip the lib+include.zip file in the same folder and the opencv_world410.7z in /x64/Debug, then it should work out of the box!
So I see that input.size() is 0 while it is 1 in the working ONNX model.
I have no idea why it is this way or how to fix it, I had 0 issues when converting the model from PyTorch to ONNX.
↧
↧
Display an image when cv2.VideoCapture(0)
Hi, I would like to know if there is a method to display a loading image when waiting for `cv2.VideoCapture(0)`
I tried to show image before calling `cv2.VideoCapture(0)` but image is displayed for a brief of moment only.
Then starts to show captured image.
↧
Links to 2.4 in opencv.org
Hi all,
I tried to find the source of the documentation of https://opencv.org/android/, but couldn't find it.
Anyhow, all the links point to 2.4, I guess they should be updated to 4.1 or at least 3.4
↧
Road Detection using Aerial Images
Hello! I'm a little new to this. I kinda wanna know if anyone has made some sort of model/classifier that can detect roads using drone aerial images?
Thank you
↧
How to do tests in Java program
Hey, I want to do testing on my OpenCV 3.6 java program and I don't know how to do that. Is there a specific module? If there is, how should I use it? If not, is there a java framework for that?
I am really new to Java and Java testing...
Thank you in advance !
↧
↧
Image stitching - need of seam finding/blending
Hello!
I am investigating the detailed stitching pipeline ([as presented here)](https://github.com/opencv/opencv/blob/master/samples/cpp/stitching_detailed.cpp). Two particular steps grabbed my attention: seam finding and blending. I have following concerns:
1. If we know when seams are why we need a blending? We could stitch images according to the seams and I do not see any need for blending in this case.
2. If we perform blending, why do we need to know where seams are? We could stitch images by blending overlapping regions of the images and I do not see any need for seam estimation in this case.
I think my understanding of the stitching process is wrong. Could you please explain where I made a mistake and how seam finding and blending works together?
↧
TensorFlow models and OpenCV DNN
Good morning everyone.
I am looking about OpenCV DNN so I downloaded a TensorFlow model called "faster_rcnn_inception_v2_coco" from here : https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md
I saw that I can use .pb and .pbtxt to load a model with DNN but in the file I downloaded I have some .meta, .index or a file named "checkpoint" and I don't know how to use these files.
Can someone help me?
Thank you.
↧
How to make fft convolution in OpenCV?
I have Matlab code for convolution in Fourier Transform but I don't know how to implement that in OpenCV. Please help me, I don't have time to read through the documents and testing it is work or not.
fftImg = fft2(I_double);
fft_gaussianKernel = fft2(Gauss_1, size(Ir, 1), size(Ir, 2); // Gauss_1 is the gaussian kernel the same size as the image.
fgauss = fftshift(fgauss);
Output = ifft2(fgauss .* fftImg); // inverse fourier transform
I hope someone can provide me the example code.
Best regards,
Hua
Best regards,
Hua
↧