opencv_createsamples "Assertion Failed" Error - opencv

I am trying to create a vec file from my positive image samples. I'm using the latest version of Opencv. The command I am using is this:
opencv_createsamples -info Positive.info -num 3750 -w 24 -h 24 -vec Positive.vec
All my images are bigger than 24x24, so I don't believe that that is the issue. I've tried searching online, but I don't find anyone with this error while doing the createsamples command. The output that I get when I run that is this:
Info file name: Positive.info
Img file name: (NULL)
Vec file name: Positive.vec
BG file name: (NULL)
Num: 3750
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 24
Height: 24
Max Scale: -1
RNG Seed: 12345
Create training samples from images collection...
OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(4.0.0-alpha) Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in cv::Mat::Mat, file c:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\matrix.cpp, line 465
This is my first time using opencv, so I'm very unclear as to what this error is. Anyone have any experience with this or can point me in the right direction to correcting the error?

This is Priyanka.
I was also getting the same error and I was trying to get resolution to it somehow.
But I could not find anything on internet.
But I am able to solve the problem successfully.
2-3 things that were missing as below:
I used opencv_annotation.exe to generate the -info (text file). This utility embeds complete image path into the file, where as the opencv_createsamples.exe expects that the images are present in the same folder as of the -info file. So what used to happen was the path of the image was getting concatenated with the path of the -info file.
i.e Suppose -info file is available at D:\MyPath\DataSet\annotations.txt and the images are at D:\MyPath\DataSet\Vehicles\*.png. In this case, while executing the opencv_createsamples.exe, the complete image path becomes D:\MyPath\DataSet\D:\MyPath\DataSet\Vehicles\image000.png, which the utility is not able to find.
So cater to the correct path kindly take care of below things
put the -info file in the same path as of images.
ensure that the -info file does not have the path for any image. It should contain only the
<image name without complete path> <object instances> <x y, width height>
With this change the image path was taken correctly and my issue got resolved.
Try doing this. It may help you.

This is Tushar Pathade, this error comes when your info.txt(file which contains information of objects to be detected) file contains some wrong information like image_name 1 0 0 0 0 or image_name 2 10 20 30 40. In first examples coordinates are (0,0,0,0) which is impossible while in second example no. of objects are 2 but coordinates of only one objects are mentioned.
So this lines produced this error. So first remove it and then run. You will not get any error then.
As priyanka mentioned above, this also need to take care of first but this will produced another error. It is nothing but image not found error. So to avoid it put info.txt file in a folder where negative images are. Basically u will see path in error so accordingly handle it.
Thank you.

I got the same error.
The error is about the bounding boxes, sometimes while creating bounding boxes you create a box outside the image pixel so that region is not get accepted and then you get this error.
Solution :
I used divide and conquer tech for this solution. What I did is I've created a new text file and in that text file I pasted some files from the original info or text file I ran the code if its creating samples then good if not then delete any one image from that text file run again*(run the create_samples again)*. do this until you get the clean file. I know this is too tedious task but this works.!
Thanks

I face the same issue now, if the num argument is less than 950 it works for me.

Related

Change video stream resolution in YoloV4 demo

Here's what shows when loading the live stream demo for Yolov4:
Webcam index: 2
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
Video stream: 2304 x 1536
Objects:
Then it starts finding objects with 2 fps.
How do I change the video stream resolution to 1080p or 720p? The frame rate is very slow and this appears to be the fix.
Can't find it within the makefile or cfg folder. Any thoughts? Is this an opencv problem?
Thanks!
cfg settings:
[net]
batch=64
subdivisions=8
# Training
#width=512
#height=512
width=320
height=320
channels=3
momentum=0.949
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.0013
burn_in=1000
max_batches = 500500
policy=steps
steps=400000,450000
scales=.1,.1
I tried with the built-in camera and connected my phone(IP) and got 1080 on both with smooth results. I didn't find anywhere to change the webcam settings which are stuck on 2304x1536. Where would camera settings be located?
After searching around for a solution to this issue myself I finally found it!
In the darknet/src/ folder is a file named "image_opencv.cpp". At lines 597 and 598 you will find the following 2 commented commands:
//cap->set(CV_CAP_PROP_FRAME_WIDTH, 1280);
&
//cap->set(CV_CAP_PROP_FRAME_HEIGHT, 960);
After trying out these commands a lot more errors showed up, this is due to yolov4 (and my install) using OpenCV 4.1.1. Which has a different syntax. Your resolution should change to 1920x1080 if you replace the two aforementioned commands with these:
cap->set(cv::CAP_PROP_FRAME_WIDTH, 1920);
cap->set(cv::CAP_PROP_FRAME_HEIGHT, 1080);
Notice that the comment slashes have been removed as to activate the commands.

Kvazaar encoder - Reading ROI file failed

While trying this command:
kvazaar -i video.yuv --input-res 1280x720 -o video_tiled.hevc --roi roi.txt --slices tiles
I get this error:
Reading ROI file failed.
invalid argument: roi=roi.txt
Any ideas?
Thanks!
Your roi.txt file must be incomplete and inadequate to the specified size.
About the roi.txt file:
(...) the first two values are the width and height, followed by
width*height delta QP values in raster order.
Here is a link to the source code giving the error: [ https://github.com/ultravideo/kvazaar/blob/f8c5bb18a4604175f20dea673d14ca66257ac0c0/src/cfg.c#L1103 ]

Duplicate photoshop level command in Imagemagick

All ,
How can I apply level (10, 245, 095) to a picture. When these level are applied in photoshop the results are different, when I am doing same in Imagemagick I get a completely different result. What am I missing
This question was also asked on the ImageMagick forum and answered by Fred (http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=26023). This is his answer:
IM -level values for min and max, depend upon the Q level of your IM compile. check convert -version. I assume it will say Q16, which means that IM is expecting values in the range of 0 to 65535. So you need to convert your values of 0 to 255 to the range of 65535 or what I usually do is convert the values to percent and use that:
10/255 = 0.03921568627451 (x100 to get percent)
245/255 = 0.96078431372549 (x100 to get percent)
so try
-level 3.921%,96.08%,0.95
The gamma value (0.95) does not need any conversion.
See:
http://www.imagemagick.org/script/command-line-options.php#level

OpenCV createsamples - invalid background description file

I'm in my OPENCV_ROOT folder and running the following command in Win-x64:
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1
maxzangle 0.5 -maxidev 40 -w 80 -h 40
-img ABSOLUTE_PATH_TO_POSITIVE_IMAGES_FOLDER\car.jpg
-bg ABSOLUTE_PATH_TO_PROJECT\negatives.txt
-vec ABSOLUTE_PATH_TO_SAMPLES_FOLDER\car.jpg.vec
-num 125
My negatives.txt looks like this:
negative_images\city01_02.jpg
negative_images\city01_04.jpg
negative_images\city01_05.jpg
negative_images\city01_06.jpg
negative_images\city01_07.jpg
This is my output:
Info file name: (NULL)
Img file name: ABSOLUTE_PATH_TO_POSITIVE_IMAGES_FOLDER\car.jpg
Vec file name: ABSOLUTE_PATH_TO_SAMPLES_FOLDER\car.jpg.vec
BG file name: ABSOLUTE_PATH_TO_PROJECT\negatives.txt
Num: 125
BG color: 0
BG threshold: 0
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 80
Height: 40
Create training samples from single image applying distortions...
Invalid background description file.
What's invalid about my negatives collection file (negatives.txt)? I tried listing the files within it both with absolute paths and with relative paths. I'm following this tutorial.
If you created the file on Windows, and running it on Linux e.g. Ubuntu, you have to change the "End of line sequence".
Click on the bottom of the editor on CR LF and change it to LF and try again!
Notepad++:
Visual Studio Code:
Geany: Documents > Set Line Endings > Convert and Set to LF (Unix)
Problem solved! The issue was simply that I had written the collection file names in Notepad++, and it all seemed fine. But when I happened to open the same file in notepad, I noticed there were no newlines after each image filename! When I added the newlines, and ran the command, the samples got created without errors!
I had the same problem. Just skip lines between addresses of the images. For example: before my negatives.dat file was:
./Negative_Images/197.
./Negative_Images/69.
./Negative_Images/510.
./Negative_Images/513.
./Negative_Images/169.png
Now it's:
./Negative_Images/197.png
./Negative_Images/69.png
./Negative_Images/510.png
./Negative_Images/513.png
./Negative_Images/169.png
Problem solved.
In my case, I was creating this bg.txt file with a script. Basically, it was doing :
for (int i = 0; i < numberOfImages; i++)
{
myDescFile << imagesFolder + std::to_string(i) + ".jpg\n";
}
I simply added another \n and the problem went away!
myDescFile << imagesFolder + std::to_string(i) + ".jpg\n\n";
EDIT:
You also have to make sure that your paths have/or\\ as separators. Else, you will be able to run the opencv_createsamples.exe cmd, won't have error, but will never see the Done at the end.
ex:L:/imgTraining/plant/bnw/0.jpg
Here's a picture of a good bg file from notepad++ (With View>Show Symbol>Show End of Line activated and Edit>EOL Conversion>Windows (CR LF) selected):
Install dos2unix on Linux by sudo apt-get install dos2unix.
And now you just need to use dos2unix YourFileName.txt.

Out of memory, plotting 24 images in 1 plot

Ho, I want to plot 24 images in 1 plot using subplot.
I've already made the empty plots using this method:
# Import everything from matplotlib (numpy is accessible via 'np' alias)
from pylab import *
# create new figure of a3 size.
figure(figsize=(16.5, 11.7), dpi=300)
# do plotting for 24 figs in 1 plot
for i in range(1, 25):
#print i
subplot(4, 6, i)
Now i want to fill my subplots with the same data in everyplot (a background to plot against) in a line plot.
I do this using the following line:
plot(myData)
Once i run the program, it crashes telling me:
"_tkinter.TclError: not enough free memory for image buffer"
So after searching the web I read that i need to close the plots after i make them so that the memory can be reused.
However, how do i do this when using subplots ?
Frank
Edit:
I think it would get easily solved if i could 2 lists, 1 with each uniq item in myData, and the second list with the number of occurences of that uniq item. any1 got tips on that ?

Resources