I am doing a project where I have to get the coordinates of each cack detected through a respected axis. I have used the euclidean distance calculation of each contour from the left most edge of the video to the centroid crack and each crack detected in order to get a store the coordinates. Right now the coordinated are moving because it is detecting the coordinates of the camera instead of the bridge. Do you have any approaches on how to get the distance between the cracks without getting the coordinates of the camera.
↧
Calculate the distance between each crack through a reference point
↧
What's the ETA for 4.4.0 python bindings?
I see that version 4.4.0 released today - awesome! Really excited to dig into it.
Anyone have an idea on the ETA for the python bindings?
> pip install opencv-contrib-python==4.4
shows that 4.3.0.36 is the latest version:
*ERROR: Could not find a version that satisfies the requirement opencv-contrib-python==4.4 (from versions: 3.4.2.16, 3.4.2.17, 3.4.3.18, 3.4.4.19, 3.4.5.20, 3.4.8.29, 3.4.9.31, 3.4.9.33, 3.4.10.35, 4.0.0.21, 4.0.1.24, 4.1.0.25, 4.1.1.26, 4.1.2.30, 4.2.0.32, 4.2.0.34, 4.3.0.36)*
Would be great to get 4.4 support!
↧
↧
Why is setting frame height and width prevents saving the webcam stream to disk?
Hello everyone.
Excuse me for the vague title. I have faced a weird situation in which, setting the frame height and width fails the stream recording on disk. That is, I have written a simple app that records my webcam streams to disk.
The issue is, in order to speed things up, I tried to reduce the frame height and width by writing:
video_capture.set(cv2.CAP_PROP_FRAME_WIDTH, 320)
video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 240)
and since I have written these two lines of code, my recordings are not saved! the files get created! but they are only 6KB only! meaning nothing goes into them!
For better understanding this is my actual webcam loop (I removed extra code so the actual loop is clear) :
def live_feed(detector, video_capture, video_writer, save_feed=False, video_feed_save_folder='feeds', scaler=1.0, acc_threshold=0.9, upper_threshold=300, hop=60, slow_motion=False, slow_motion_threshold=0.02, hard_rescale=False, **kwargs):
try:
video_capture.set(cv2.CAP_PROP_FRAME_WIDTH, 320)
video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 240)
while detector.is_running():
# Capture frame-by-frame
ret, frame_orig = video_capture.read()
if ret == False:
print("in Detector: Failed to retrieve frame(is webcam ready?)")
break
if hard_rescale:
frame = Detector.image_resize(frame_orig, width=48)
else:
frame = cv2.resize(frame_orig,
None,
fx=scaler,
fy=scaler,
interpolation=cv2.INTER_LINEAR)
print(f'{i}:oiginal frame {frame_orig.shape} : new frame {frame.shape}')
if detector.get_display_live_feed():
# Display the resulting frame
cv2.imshow('FV ', frame_orig) # or frame
if slow_motion:
time.sleep(slow_motion_threshold)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
if detector.save_feed:
video_writer.write(frame_orig)
video_capture.release()
if detector.save_feed:
video_writer.release()
cv2.destroyAllWindows()
except Exception as exp:
print(f'Detector: {exp.args}')
raise exp
and this is how I create Video_capture and video_writers :
def _setup_feed_archive(self):
self.frame_h, self.frame_w = (240, 320)
self.archive_file_path = None
self.video_capture = None
self.video_writer = None
if self.source_type == SourceType.Webcam:
webcam_source = self.input_source + cv2.CAP_DSHOW if platform.system() == 'Windows' else self.input_source
st, frame_orig = cv2.VideoCapture(webcam_source).read()
if frame_orig is None:
webcam_source = self.input_source
self.video_capture = cv2.VideoCapture(webcam_source)
elif self.source_type == SourceType.VideoStream:
print(f'VideoStream Detected. input comming from: {self.input_source}')
self.video_capture = cv2.VideoCapture(self.input_source)
if self.video_capture != None:
ret, frame_orig = self.video_capture.read()
print(f'image is valid?: {ret}')
(self.frame_h, self.frame_w, _) = frame_orig.shape
if self.get_save_stream_status():
dtime_str = datetime.now()
todays_dtime = dtime_str.strftime("%a %x %X").replace(':', '_').replace('/', '_').replace(' ', '__')
filename = f'recording_{todays_dtime}.avi'
self.archive_file_path = os.path.join(self.video_feed_save_folder, filename)
if not os.path.exists(self.video_feed_save_folder):
os.mkdir(self.video_feed_save_folder)
print(f'archive path: {self.archive_file_path}')
# ffmpeg should be installed or configuring this becomes a headache
self.video_writer = cv2.VideoWriter(self.archive_file_path, cv2.VideoWriter_fourcc(*'XVID'), 6, (self.frame_w, self.frame_h))
So I'm completeley confused why the video_writer doesnt record the stream. Everything else works just fine, except when those two lines are specified, the video_writer doesnt record anything.
My webcam is a logitech C270. could this be becasue of the webcam I have, or is it an OpenCV bug ?
what should I be looking for to get this fixed, as I dont get any exceptions or any clues. everything works except writing to files! if I comment out those two lines, everything starts working just fine!!
By the way I'm using anaconda 3 (python3.7.4, and I'm on windows 10, and I use opencv 4.1.2 )
I'd greatly appreciate if anyone could shed somelight on this or give me some hints, or suggestions to follow in order to get this to work or know what is happening.
Thank you very much in advance
↧
Calculate (ORB) descriptors for arbitrary image points
I have a set of points in an image (`vector`) and I want to calculate their descriptors. I want to use the ORB descriptor for this. It is possible to calculate the descriptors for any set of keypoints (`vector`), but they have additional information like size and rotation (the BRIEF descriptor in ORB is very sensitive to rotation, so it's not appropriate just use default keypoint parameters). The keypoint detector finds this additional information, but I'm curious if there is a way to do what it does when the point coordinate is already known.
The ORB keypoint detector roughly does these steps:
1. FAST keypoint detection (with image pyramids)
2. Calculate the Harris corner response (aka corner measure, corner score, corner criterion etc.)
3. Calculate mass center and inertia in the keypoint's neighborhood to find the rotation
Then the compute-function calculates the rotation-compensated BRIEF descriptor.
In short I wish to circumvent step 1. in the ORB detector. The image pyramid might complicate things, but for my use-case, loosing scale invariance is a reasonable compromise.
↧
Finding suitable HSV color
Hi, Im a new learner in OpenCV. Could you please help me in finding the suitble hsv range color for both team and the goalkeeper. I have tested a lot of range, but still does not get a good result. Please help me. Color range that I need is orange(left keeper), green (right keeper), yellow/brown(for left team) and purple/pink(for right team). Could you provide an example. Thanks
import cv2
import numpy as np
cap = cv2.VideoCapture("pitch2.mkv")
kernel_dil = np.ones((0,0), np.uint8)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,3))
fgbg = cv2.createBackgroundSubtractorMOG2(history=0, varThreshold=100, detectShadows=False)
while True:
#read frame
ret, frame1 = cap.read()
#screen Resize
frame = cv2.resize(frame1,(1364,700),fx=0,fy=0, interpolation = cv2.INTER_CUBIC)
#warpPerspective
width,height = 682,350
#width,height = 1023,525
pts1 = np.float32([[426,90],[940,90],[11,652],[1353,652]])
pts2 = np.float32([[0,0],[width,0],[0,height],[width,height]])
matrix = cv2.getPerspectiveTransform(pts1,pts2)
warpOutput = cv2.warpPerspective(frame,matrix,(width,height))
#implement ROI
mask = np.zeros(warpOutput.shape, dtype=np.uint8)
mask.fill(255)
roi_corners = np.array([[(0,340), (682,340), (682,20), (0,20)]], dtype=np.int32)
mask = cv2.fillPoly(mask, roi_corners, 0)
masking = cv2.bitwise_or(warpOutput, mask)
if ret == True:
fgmask1 = fgbg.apply(masking,mask)
fgmask2 = cv2.morphologyEx(fgmask1, cv2.MORPH_OPEN, kernel)
dilation = cv2.dilate(fgmask2, kernel_dil, iterations = 0)
(contours,hierarchy) = cv2.findContours(dilation, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
XContour = []
maxX = 0
xBefore = 0
XCont = []
max_x = 0
xLast = 0
for pic, contour in enumerate(contours):
area = cv2.contourArea(contour)
x,y,w,h = cv2.boundingRect(contour)
if(area>5): #set to 2 to undetect the ball
player_img = warpOutput[y:y+h,x:x+6]
player_hsv = cv2.cvtColor(player_img,cv2.COLOR_BGR2HSV)
lower_purple = np.array([150,150,100])
upper_purple = np.array([184,255,255])
lower_yellow = np.array([70,150,100])
upper_yellow = np.array([100,255,255])
lower_green = np.array([70,150,100])
upper_green = np.array([100,255,255])
lower_orange = np.array([70,150,100])
upper_orange = np.array([100,255,255])
mask_purple = cv2.inRange(player_img, lower_purple, upper_purple)
output_purple = cv2.bitwise_and(player_hsv, player_img, mask = mask_purple)
resPurple = cv2.cvtColor(output_purple,cv2.COLOR_HSV2BGR)
resPurple = cv2.cvtColor(resPurple,cv2.COLOR_BGR2GRAY)
nzCountPurple = cv2.countNonZero(resPurple)
mask_yellow = cv2.inRange(player_img, lower_yellow, upper_yellow)
output_yellow = cv2.bitwise_and(player_img, player_img, mask = mask_yellow)
resYellow = cv2.cvtColor(output_yellow,cv2.COLOR_HSV2BGR)
resYellow = cv2.cvtColor(resYellow,cv2.COLOR_BGR2GRAY)
nzCountYellow = cv2.countNonZero(resYellow)
mask_green = cv2.inRange(player_img, lower_green, upper_green)
output_green = cv2.bitwise_and(player_img, player_img, mask = mask_green)
resGreen = cv2.cvtColor(output_green,cv2.COLOR_HSV2BGR)
resGreen = cv2.cvtColor(resGreen,cv2.COLOR_BGR2GRAY)
nzCountGreen = cv2.countNonZero(resGreen)
mask_orange = cv2.inRange(player_img, lower_orange, upper_orange)
output_orange = cv2.bitwise_and(player_img, player_img, mask = mask_orange)
resOrange = cv2.cvtColor(output_orange,cv2.COLOR_HSV2BGR)
resOrange = cv2.cvtColor(resOrange,cv2.COLOR_BGR2GRAY)
nzCountOrange = cv2.countNonZero(resOrange)
if(nzCountPurple>=5):
cv2.rectangle(warpOutput, (x,y), (x+w,y+h), (0,255,255), 1)
elif(nzCountYellow>=5):
cv2.rectangle(warpOutput, (x,y), (x+w,y+h), (0,0,0), 1)
elif(nzCountGreen>=5):
cv2.rectangle(warpOutput, (x,y), (x+w,y+h), (255,255,0), 1)
elif(nzCountOrange>=5):
cv2.rectangle(warpOutput, (x,y), (x+w,y+h), (255,0,0), 1)
else:
cv2.rectangle(warpOutput, (x,y), (x+w,y+h), (0,0,255), 1)
# cv2.line(warpOutput, (110,144), (110,232), (255,0,0), 1)
cv2.imshow("FullScreen", frame)
cv2.imshow("WarpOutput", warpOutput)
key = cv2.waitKey(10)
if key == ord("q"):
print("Video Stopped")
break
cap.release()
cv2.destroyAllWindows()
↧
↧
How to Generate a .pbtxt from .pb which is trained with the New TF 2 Object detection API
Hi, So I've trained a detector using SDD with mobilnet V2 and trained another one using SSD with efficientdet d0.
Now I need to get the pbtxt file so I can use these models inside the dnn module. Previously I managed to generate a pbtxt and use it in TF 1 but now I'm trying with TF2. The issue is that the pbtxt generator [here](https://github.com/opencv/opencv/wiki/TensorFlow-Object-Detection-API) only works for models trained with TF Object detection API 1 so I was wondering how to go about getting a pbtxt for a .pb file in version 2
↧
Stereo Camera Calibration - World Origin
Hello,
I have some questions about stereo calibration and I also wanted to verify that my understanding so far is correct.
I am working on a project where I want to get 3D coordinates from a stereo camera setup. I am working in C++ using the opencv_contrib aruco library for ChArUco board detection. So far I have calibrated both of my cameras intrinsic parameters (camera matrix, and distortion coefficients for each) by detecting ChArUco board corners and refining them, then I use cv::aruco::calibrateCameraCharuco to get intrinsics. Next, I create a stereo pair by gathering new images where both cameras can see the calibration board. I detect ChArUco board corners from each cameras viewpoint and run cv::stereoCalibrate. Running stereoCalibrate provides me with the extrinsic parameters (rotation matrix, and translation matrix) for the transformation from camera 1's coordinate system to camera 2's coordinate system (correct me if I'm wrong!).
Now that I have my intrinsic parameters for each camera, and my extrinsic parameters relating the two camera coordinate systems, I run cv::stereoRectify to obtain projection matrices for each camera that transform the camera views to be planar with one another. Next, I wanted to run cv::triangulatePoints to see how accurate my 3D point is. Running this triangulation function I get a result returned to me, however, I believe that this 3D point if relative to the world origin. **I am wondering how/where OpenCV sets the world origin, and I would like to know how I should go about setting my own world origin.**
Here is a list breakdown of my current workflow:
1. Gather a set of calibration images for each camera
2. Use each cameras set of images to calibrate intrinsic parameters
3. Gather a new set of calibration images for the stereo pair, where both cameras can view the ChArUco board
4. Use the images to calibrate extrinsic parameters of the stereo pair
*And now the part I'm not sure how to do...*
5. Use the calibrated cameras with extrinsic parameters to determine 3D points relative to the world origin in my workspace
Thanks for the help!
↧
Compiling Tracker from tutorial leads to error: ‘Tracker’ was not declared in this scope
Hello, I have been using opencv in python without issues. I am now trying to switch to cpp, which I am new to. I have recently reinstalled opencv and compiled it with [opencv_contrib](https://github.com/opencv/opencv_contrib) following the instructions in the readme. I am using the tracking features of opencv for my project.
When I go to make my file I get the following error:
/home/sydney/Desktop/projects/Leaf_Tracking_cpp/tracker.cpp: In function ‘int main(int, char**)’:
/home/sydney/Desktop/projects/Leaf_Tracking_cpp/tracker.cpp:33:9: error: ‘Tracker’ was not declared in this scope
33 | Ptr tracker;
| ^~~~~~~
/home/sydney/Desktop/projects/Leaf_Tracking_cpp/tracker.cpp:33:16: error: template argument 1 is invalid
33 | Ptr tracker;
| ^
/home/sydney/Desktop/projects/Leaf_Tracking_cpp/tracker.cpp:37:19: error: ‘Tracker’ is not a class, namespace, or enumeration
37 | tracker = Tracker::create(trackerType);
| ^~~~~~~
/home/sydney/Desktop/projects/Leaf_Tracking_cpp/tracker.cpp:76:12: error: ‘selectROI’ was not declared in this scope; did you mean ‘select’?
76 | bbox = selectROI(frame, false);
| ^~~~~~~~~
| select
/home/sydney/Desktop/projects/Leaf_Tracking_cpp/tracker.cpp:82:12: error: base operand of ‘->’ is not a pointer
82 | tracker->init(frame, bbox);
| ^~
/home/sydney/Desktop/projects/Leaf_Tracking_cpp/tracker.cpp:91:26: error: base operand of ‘->’ is not a pointer
91 | bool ok = tracker->update(frame, bbox);
| ^~
make[2]: *** [CMakeFiles/tracker.dir/build.make:63: CMakeFiles/tracker.dir/tracker.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/tracker.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I notice that others have had the same error [here](https://answers.opencv.org/question/201817/tried-to-compile-tracker-from-tutorial-and-got-error-tracker-was-not-declared-in-this-scope-ptrtracker-tracker-trackerkcfcreate/) but its not clear how they were able to get the code to compile.
Any suggestions on how to solve this would be greatly appreciated! Thank you!
One thing to note is that when I use "#include " I get an error that it can't find tracking.hpp so I have replaced that line in the sample code with "#include ".
↧
Is it possible to use tee in gstreamer pipeline inside VideoCapture() API?
I am trying to use same camera source for reading frames using opencv videoCapture() API and RTMP streaming.For this I am using tee in gstreamer pipeline inside Videocapture () api as shown below
cv::VideoCapture cap("nvarguscamerasrc sensor-id=0 ! video/x-raw(memory:NVMM), width=1920, height=1080, format=NV12, framerate=10/1 ! tee name=t t. ! queue ! omxh264enc profile=8 bitrate=1000000 ! h264parse ! flvmux ! rtmpsink location= t. ! queue ! nvvidconv flip-method=0 ! video/x-raw, width=640, height=480, format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink ",cv::CAP_GSTREAMER)
But I am not getting the desired output. I am getting only two frames .RTMP streaming is not working.
Is it possible to do like this? I am new to gstreamer pipeline. So kindly help me.
Thanks in advance
↧
↧
CUDA headers still appear even if -DWithCUDA=OFF ?
- OpenCV => 3.4.11
- Operating System / Platform => OSX 10.15.4
I am wondering whether cuda related functionalities are useful for using opencv in ios projects and I suspect not. When compiling with
```
python opencv/platforms/ios/build_framework.py ios \
--without gpu --without contrib --without dnn --without highgui \
--without legacy --without ml --without nonfree --without objdetect \
--without photo --without stitching --without video --without videoio \
--without videostab --without flann --without dnn --without calib3d \
--without features2d --without gapi --without java_bindings_generator \
--without imgcodecs --iphoneos_archs=arm64 --dynamic \
--without world --disable-bitcode
```
I can still see cuda related headers are included in the output. Cuda related headers still appear even if I manually added `-DWITH_CUDA=OFF` in `opencv/platforms/ios/build_framework.py`
↧
don't know how to predict classes with RCNN ResNet50 and the dnn method
I don't know how to predict classes with the RCNN ResNet50 model. I can successfully predict the bounding boxes but I don't know how to predict the right class.
I've downloaded the pretrained model weights and config files from the [OpenCV GitHub Site](https://github.com/opencv/opencv/wiki/TensorFlow-Object-Detection-API#use-existing-config-file-for-your-model). Link to the [object_detection_classes_coco.txt](https://github.com/opencv/opencv/blob/master/samples/data/dnn/object_detection_classes_coco.txt).
I would be really thankful if somebody could help me or show me in the right direction. If it is not possible that would be also help me further. Thank you very much in advance :)
This is my code:
%matplotlib inline
import cv2 as cv
import matplotlib.pyplot as plt
cvNet = cv.dnn.readNetFromTensorflow('frozen_inference_graph.pb', 'faster_rcnn_resnet50_coco_2018_01_28.pbtxt')
# Category Names
coco_names = "object_detection_classes_coco.txt"
classes = open(coco_names).read().strip().split("\n")
# define path
img_path = 'img\elephant.jpg'
# read picture
img = cv.imread(img_path, cv.IMREAD_UNCHANGED)
img = cv.cvtColor(img,cv.COLOR_BGR2RGB)
img = cv.resize(img, (300, 300), interpolation=cv.INTER_AREA)
rows = img.shape[0]
cols = img.shape[1]
blob = cv.dnn.blobFromImage(img, size=(300, 300), swapRB=True, crop=False)
cvNet.setInput(blob)
cvOut = cvNet.forward()
# loop over the number of detected objects
for i in range(0, cvOut.shape[2]):
# extract the class ID of the detection along with the confidence
# (i.e., probability) associated with the prediction
classID = int(cvOut[0, 0, i, 1])
confidence = cvOut[0, 0, i, 2]
print("Klasse: {} \n Wahrscheinlichkeit: {}".format(classes[classID],confidence))
for detection in cvOut[0,0,:,:]:
score = float(detection[2])
if score > 0.3:
left = detection[3] * cols
top = detection[4] * rows
right = detection[5] * cols
bottom = detection[6] * rows
cv.rectangle(img, (int(left), int(top)), (int(right), int(bottom)), (23, 230, 210), thickness=2)
plt.figure(1)
plt.imshow(img)
I've only found this [tutorial](https://www.pyimagesearch.com/2018/11/19/mask-r-cnn-with-opencv/) that is kinda similar but I've tried it out for the faster R-CNN with ResNet50 but it didn't work.

↧
Assign to a single channel of GpuMat
I have some code which generates separate grayscale images, and then I composite them into the red, green, and blue channels of a color image, like so:
combined = numpy.zeros((frame.shape[0], frame.shape[1], 3)
combined[...,2] = red_img
combined[...,1] = green_img
combined[...,0] = blue_img
I'm updating the code to use the CUDA backend and so instead of using a Numpy array I need to create a `cuda_GpuMat` instance. However, these are 2D only.
What is the recommended solution to copy to only one channel?
↧
Android app Force closed by memory leak
Hey everyone.
I'm trying to build a app,which can detect red color form input image ,
and do Hough line transform ,after sent the result to screen.
i think i finish the program,but the program will be Force closed,about every 30~50 sec.
i'm using opencv 2.4.10 (for android),and eclipse to build the program;
the program is revised from the OPENCV sample "example-tutorial-1-camerapreview",
and i revised "public Mat onCameraFrame(CvCameraViewFrame inputFrame) " into below
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
Mat sourceimage = inputFrame.rgba();
Imgproc.cvtColor(sourceimage , sourceimage, Imgproc.COLOR_RGBA2RGB);
Imgproc.cvtColor(sourceimage , sourceimage, Imgproc.COLOR_BGR2HSV);
Mat mRgba = new Mat();
Mat lines = new Mat();
Mat filter2= new Mat();
Core.inRange(sourceimage, new Scalar(50, 70, 100), new Scalar(150, 250, 250), filter2);
mRgba=filter2.clone();
Imgproc.cvtColor(mRgba , mRgba, Imgproc.COLOR_GRAY2RGBA);
Imgproc.Canny(filter2, filter2, 80, 100, 5, true);
Imgproc.HoughLinesP(filter2, lines, 1, Math.PI/180, 125, 20, 20);
for (int x = 0; x < lines.cols(); x++)
{
double[] vec = lines.get(0, x);
double x1 = vec[0],
y1 = vec[1],
x2 = vec[2],
y2 = vec[3];
Point start = new Point(x1, y1);
Point end = new Point(x2, y2);
Core.line(mRgba, start, end, new Scalar(255,0,0), 2);
}
return mRgba;
}
I think " Core.inRange(sourceimage, new Scalar(50, 70, 100), new Scalar(150, 250, 250), filter2);"
will cause the program Force closed,because when i trying to avoid program Force closed,i have removed "Core.inRange(sourceimage, new Scalar(50, 70, 100), new Scalar(150, 250, 250), filter2);"
from program,though program can't show image to screen ,but the program won't be Force closed.
Does anyone know how to solve this problem?
maybe the problem is not caused by "Core.inRange"
finally ,i'm apology about my poor English,and thanks for your response.
↧
↧
getPerspectiveTransform & perspectiveTransform
I'm using `getPerspectiveTransform` & `perspectiveTransform` to map points from a camera frame (let's call it "perspective cam") taken from an arbitrary (but fixed) position to points on a bird's-eye view of the same area (let's call it "bird cam").
I have a quadrilateral overlaying the perspective cam frame (q1). I have the corresponding quadrilateral overlaying my bird cam frame (q2). I.e. I manually specified four points that map to each other.
I use `getPerspectiveTransform(q1,q2)` and then I use `perspectiveTransform` with the resulting matrix to map arbitrary points from the perspective cam frame to the bird cam frame.
Similarly, I use `getPerspectiveTransform(q2,q1)` and then I use `perspectiveTransform` with the resulting matrix to map arbitrary points from the bird cam frame to the perspective cam frame.
Finally, my question: **Is the mapping always correct?** I.e. assuming that neither frame has any barrel distortion, is can the mapping be relied upon as being accurate, or is it just a rough correspondence that depends on the perspective cam's positioning?
Thank you!
↧
opencv install not occuring
when I try to install Opencv within the ubuntu 20.04 (has python3) using the following command:
"sudo apt install python3-opencv"
I am getting the following error message:
" E: Unable to locate package python3-opencv"
Why? And what do I need to do?
↧
Zoom lenses to calibrate
Hi there,
I have been using fixed (prime) lenses so far for chess board calibration and aruco marker detection. Question: is it possible to use the zoom lenses and calibrate it to get intrinsic matrix and distortion. if yes, Would appreciate details,
Thank you in advance
↧
loading tensorflow model with dropout layers by opencv
hi everyone, recently i tried to use opencv to load tensorflow .pb file, but i got following problems:
i trained my network with dropout layers and saved it as a .pb file, but when i use function readNetFromTensorflow to load this model, i got the error messages:
OpenCV(4.1.0) Error: Unspecified error (More than one input is Const op) in cv::dnn::dnn4_v20190122::`anonymous-namespace'::TFImporter::getConstBlob, file c:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\tensorflow\tf_importer.cpp, line 522
OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(4.1.0) Error: Unspecified error (More than one input is Const op) in cv::dnn::dnn4_v20190122::`anonymous-namespace'::TFImporter::getConstBlob, file c:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\tensorflow\tf_importer.cpp, line 522
but when i removed the dropout layers and retrained the network, opencv can load the generated .pb file successfully. I guess the problem is in the dropout layers but i don't know how to fix it, is there any way to deal with this?
Thanks for any help in advance!
↧
↧
How to convert cv2.cuda_GpuMat to cv::cuda::GpuMat
I am trying to create a wrapper in pybind11 to create part of the code in c ++. The problem is that I have to transfer a cuda_gpuMat image to its namesake cv :: cuda :: GpuMat in c ++.
Is there a way?
at::Tensor gpumat2torch(cv::cuda::GpuMat& frame) {
at::ScalarType torch_type = get_torch_type(frame.type());
auto options = torch::TensorOptions().dtype(torch_type).device(torch::kCUDA);
std::vector sizes = {1,
static_cast(frame.channels()),
static_cast(frame.rows),
static_cast(frame.cols)};
return torch::from_blob(frame.data, sizes, options);
}
PYBIND11_MODULE(gpumat, m) {
m.doc() = "gpumat2torch function!";
m.def("gpumat2torch", &gpumat2torch, "A function to convert GpuMat to CudaTorch");
#ifdef VERSION_INFO
m.attr("__version__") = VERSION_INFO;
#else
m.attr("__version__") = "dev";
#endif
}
↧
Surface Matching never get any results with any data, why?
Hi
Im trying to get working the Surface Matching Sample code from [surface_matching](https://docs.opencv.org/3.0-beta/modules/surface_matching/doc/surface_matching.html). Im able to compile the code then when run with
./surface_matching /home/surface_matching/coke.ply /home/surface_matching/01.ply
I got this Error
$ ./surface_matching /home/admini/surface_matching/coke.ply /home/admini/surface_matching/01.ply
****************************************************
* Surface Matching demonstration : demonstrates the use of surface matching using point pair features.
* The sample loads a model and a scene, where the model lies in a different pose than the training.
* It then trains the model and searches for it in the input scene. The detected poses are further refined by ICP
* and printed to the standard output.
****************************************************
Running on 64 bits
Running without OpenMP and without TBB
Training...
Training complete in 0.100169 sec
Loading model...
Starting matching...
Segmentation fault (core dumped)
Training is complete and starts matching but then Segmentation fault. What can be the problem?
Here the object model file:

Any help?
Thanks
↧
Extracting vertical masks into separate images in OpenCV
I''m new to opencv, I am essentially trying to extract a table from an image, and I need to be able to get the columns separately,
I have come across this code here https://stackoverflow.com/questions/60521925/how-to-detect-the-horizontal-and-vertical-lines-of-a-table-and-eliminate-the-noi
It almost accomplishes that I need in terms of segmenting the table vertically. The issue is that I need those separate segments saved as separate images. Is there way to go about doing that?
import cv2
import numpy as np
# Load image, grayscale, Gaussian blur, Otsu's threshold
image = cv2.imread('x.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (3,3), 0)
thresh = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
# Detect vertical lines
vertical_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1,50))
vertical_mask = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, vertical_kernel, iterations=1)
# Combine masks and remove lines
table_mask = cv2.bitwise_or(0,vertical_mask)
image[np.where(table_mask==255)] = [255,255,255]
cv2.imshow('image', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
The code above removes the vertical lines, however I need those vertical images in separate files.
↧