OpenCV error: Image step is wrong - linux

I'm going through this tutorial: http://docs.opencv.org/trunk/modules/contrib/doc/facerec/tutorial/facerec_video_recognition.html#creating-the-csv-file
Everything goes well, but running the face recognition script gives this error:
OpenCV Error: Image step is wrong (The matrix is not continuous, thus its number of rows can not be changed)
I'm using Ubuntu so I'm not exactly sure how to implement the solution found here: Getting OpenCV Error "Image step is wrong" in Fisherfaces.train() method
I rebuilt in debug mode but that had no effect.

Recently I faced the same error with this face recognition example. I got rid of the error by giving same ratio(1:1) images.
Crop the images using this script (see this as well Command line batch image cropping tool)
#!/bin/bash
width=92;
height=92;
x_offset=0;
y_offset=10;
filelist=`ls | grep '.pgm'`
for image_file in $filelist
do
convert -crop ${width}x${height}+${x_offset}+${y_offset} \
$image_file $image_file
done
this will crop the images in a folder, so u need to put this script in the same directory where your images are.
Also you should give absolute path inside the csv file.

Related

How to run Tutorial: Simple LSTM on fairseq

While trying to learn fairseq, I was following the tutorials on the website and implementing:
https://fairseq.readthedocs.io/en/latest/tutorial_simple_lstm.html#training-the-model
However, after following all the steps, when I try to train the model using the following:
! fairseq-train data-bin/iwslt14.tokenized.de-en \ --arch tutorial_simple_lstm \ --encoder-dropout 0.2 --decoder-dropout 0.2 \ --optimizer adam --lr 0.005 --lr-shrink 0.5 \ --max-tokens 12000
I receive an error:
`fairseq-train: error: argument --arch/-a: invalid choice: 'tutorial_simple_lstm' (choose from 'fconv', 'fconv_iwslt_de_en', 'fconv_wmt_en_ro', 'fconv_wmt_en_de', 'fconv_wmt_en_fr', 'fconv_lm', 'fconv_lm_dauphin_wikitext103', 'fconv_lm_dauphin_gbw', 'transformer', 'transformer_iwslt_de_en', 'transformer_wmt_en_de', 'transformer_vaswani_wmt_en_de_big', 'transformer_vaswani_wmt_en_fr_big', 'transformer_wmt_en_de_big', 'transformer_wmt_en_de_big_t2t', 'bart_large', 'bart_base', 'mbart_large', 'mbart_base', 'mbart_base_wmt20', 'nonautoregressive_transformer', 'nonautoregressive_transformer_wmt_en_de', 'nacrf_transformer', 'iterative_nonautoregressive_transformer', 'iterative_nonautoregressive_transformer_wmt_en_de', 'cmlm_transformer', 'cmlm_transformer_wmt_en_de', 'levenshtein_transformer', 'levenshtein_transformer_wmt_en_de', 'levenshtein_transformer_vaswani_wmt_en_de_big',....
Some additional info: I am using google colab. And I am writing the entire code until train step into .py file and uploading it to fairseq/models/... path as per my interpretation of the instructions. I am following the exact tutorial in the link.
And, before running it on colab, I am installing fairseq using:
!git clone https://github.com/pytorch/fairseq %cd fairseq !pip install --editable ./
I think this error happens because the command line argument created as per the tutorial has not been set properly.
Can anyone please explain if on any step I would need to do something else.
I would be grateful for your inputs as for a beginner learner such help from the community goes a long way.
Seems you didn't register the SimpleLSTMModel architecture as follow. Once the model is registered you can use it with the existing Command-line Tools.
#register_model('simple_lstm')
class SimpleLSTMModel(FairseqEncoderDecoderModel):
...
.
.
...
Please note that copying .py files doesn't mean you have registered the model. To do so, you need to execute the .py file that includes abovementioned lines of code. Then, you'll be able to run the training process using existing command-line tools.
You should put your .py into:
fairseq/fairseq/models
not to fairseq/models

Can't read .avi files using Python OpenCV 4.1.2-dev

I wanna run my opencv3.1 programs, but when i try to read a file using cv2.VideoCapture shows me the error:
error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): ./../images/walking.avi in function 'icvExtractPattern'
But, when i using the camera with cv2.VideoCapture(0) it works perfectly. I verify the file path and using the relative and the absolute path, but still not working.
I gonna wait for your answers.
Thanks a lot
Originally I used cv2.VideoWriter_fourcc(*'XVID') getting the same error
switch the (*'XVID') to (*'MJPG')
I am using a raspberry pi Gen. 4 (4GB) with image: Raspbian Buster Lite

Error while executing convert (imagemagick) in cygwin

I am trying to resize an image in windows. I have a shell script which I am executing using cygwin. Script is working fine. But I am unable to execute convert (imagmagick). I am getting the following error when I am executing the convert command.
`$ convert /cygdrive/c/Users/myUser/Desktop/9121.JPG -resize 50% a.png
Error : convert.exe: unable to open image /cygdrive/c/Users/myUser/Desktop/9121.JPG': No such file or directory # error/blob.c/OpenBlob/2701.
convert.exe: no images defineda.png' # error/convert.c/ConvertImageCommand/3230.
Please help me. Thanks.
Please set path variable to convert.exe path location, and then execute convert command

Installing Image Magick with Ghostscript

Hello fellow Stackers,
Currently I am working on a website which requires the ability to handle, manipulate, create and save PostScript encoded files. Research on the topic pointed me towards two PHP classes called Imagick and MagickWand – both of which use Image Magick, which in turn depends on Ghostscript. Unfortunately the GD PHP class is not up to the task.
I am performing the installation processes on a server running GNU/Linux via SSH from my Mac with OS X 10.9.1. Any help would be much appreciated. If any other details are needed, please inform me and I will do my absolute best to provide them.
Thus far, I have managed to make Image Magick and Ghostscript function independently – while simultaneously installed on the same system. However I was not able to install Ghostscript accordingly for it to function as an Image Magick delegate. From Terminal I was able to run the convert and gs commands successfully. At the time I was able to use the Imagick PHP class to perform the required tasks – such as detecting Color Space – on rasterised images.
As it stands Image Magick has been uninstalled from the server. I was not able to uninstall Ghostscript correctly. So my first question is: how on earth do I uninstall Ghostscript 9.10? It seems Ghostscript does not include an uninstall in its Makefile, ie: make uninstall returns make: *** No rule to make target 'uninstall'. Stop..
I have done some research and it seems that I should have compiled the Ghostscript shared library first: http://www.linuxfromscratch.org/blfs/view/svn/pst/gs.html
Naturally I attempted to perform the steps in the article on Linux from Scratch. I have removed expat, freetype, lcms2, jpeg and libpng. I have performed ./configure with the suggested commands. I have also performed make and make so, both of which fail and exit, returning:
pngrutil.c:(.text+0x3cb): undefined reference to 'inflateReset2'
collect2: ld returned 1 exit status
make: *** [bin/gs] Error 1.
edit: I have since narrowed this down to be related to Zlib.
I am looking for either an alternative to Imagick and MagickWand (which I was not able to find), insights into what is going wrong during the installation process or what might be done to resolve the current error.
Thank you all in advance.
A manual process to uninstall may be required if there is no uninstall defined for the makefile.
This has been discussed in the question What's the opposite of 'make install', ie. how do you uninstall a library in Linux?.
I ditched the idea of using Ghostscript as an Image Magick Delegate, not only because the installation process was not working out for but, but also due to the fact that my research taught me that Image Magick rasterises all input files.
Instead I used the PHP exec() function to directly execute Ghostscript.

Node.js ImageMagick & GM both cause error 127 when trying to load a valid image

I have a node app which accepts an uploaded image (using formidable) and stores it into an Amazon S3 bucket. Before it is saved to S3, I want to get the image's width, height, etc. for future consideration. I found this question which helped: Opening images on NodeJS and finding out width/height
However, when I try to open the image with imagemagick (or gm, for that matter, I've tried both) I get error 127. Specifically, imagemagick reports:
{"timedOut":false,"killed":false,"code":127,"signal":null}
I know the file exists (because it is properly uploaded to the S3 bucket), and I can manipulate it (eg, rename) via fs, but I cannot find any documentation on error code 127 to determine why IM fails. Thinking that perhaps there was something odd about the file uploaded to formidable causing it to not be read properly, I tried using imagemagick to load a simple "test.jpg" image in the same folder:
im.identify('test.jpg', function(err, features){
if(!err)
{
// my image processing code
}
else
{
// my err handling code; spits out the error above
}
});
Unfortunately, this fails in the exact same manner, even though I'm sure test.jpg is a good and properly formatted image.
So, can anybody help me understand what error 127 is and why ImageMagick would throw it when fs is able to read the file just fine...?
These are a couple of php commands to find the path to Imagemagick which should confirm it is installed.
Sometimes in php there is a problem just using convert and you need to use the full path; something like /usr/local/bin/convert
echo "<pre>";
system("type convert");
system('which convert',$path); print_r($path);
echo "</pre>";
I know you are not using php but you should still be able to use the methods.
Make sure "convert" is installed
sudo apt-get update
sudo apt-get install imagemagick --fix-missing
Derp. I didn't have ImageMagick itself installed. I assumed that the NPM installation was all that was required; did not realize there were additional dependencies, and the error message was a bit cryptic ;)
I had the same problem, just install Graphics Magick, http://www.graphicsmagick.org/
test if your intallation works as the wizard suggest and that's it.

Resources