libtiff: TIFFGetField returns incorrect image' width and height - image-processing

I have a tiff file with 1736x1160x48b resolution. I'm using libtiff 4.0 dll and I have noticed that the resolution being read from the TIFFGetField function is incorrect. I'm getting 156 width and 104 height which is too low.
TIFF* pTiff;
pTiff = dll.OpenTIFF(szFilePath, (char*)("r"));
if (pTiff == nullptr) {
return LPROCESS_FAILED;
}
uint32_t uWidth = 0;
uint32_t uHeight = 0;
int ret = 0;
ret = dll.TIFFGetField(pTiff, TIFFTAG_IMAGEWIDTH, &uWidth);
ret = dll.TIFFGetField(pTiff, TIFFTAG_IMAGELENGTH, &uHeight );
// ret value is 1 on both lines
Do I need to update my tiff library to 4.5? Is there a fix on the latest version? or is this a format error on the image side? Though when I try to open the image on other photo viewing application, it was able to interpret correctly.
Update: I used libtiff 4.5 latest release and I'm still getting incorrect width and height. My guess is that the image I'm trying to load is not yet fully supported by libtiff. Here is the details of the image from exiftool:

Related

Cimg in embedded hardware

I load a jpg into embedded system memory on an Stm32 board with assembly code via .incbin and copy the data to an alternate buffer via std::copy. The image is displayed on an attached lcd screen and is decompressed with picoimage and all is well. I wish to apply image effects beforehand and I use CImg which seems to be small and portable. Compared to others I simply have to place the header in working directory and I have a grayscale code below; however, I have to same issue as when I attempted to alter the code by hand the screen appears black. I can't seem to find a proper fix for it. Are their any suggestions. For some reason I feel as though CImg is not aware it is a jpg file and opts to load and operate on the whole compressed data. Is their a work around?
CImg<uint8_t> image(_buffer,_panel->getWidth(),_panel->getHeight(),1,1,true);
int width = image.width();
int height = image.height();
//int depth = image.depth();
//New grayscale images.
//CImg<unsigned char> gray1(width,height,depth,1);
//CImg<unsigned char> gray2(width,height,depth,1);
unsigned char r,g,b;
unsigned char gr1 = 0;
unsigned char gr2 = 0;
/* Convert RGB image to grayscale image */
for(int i=0;i<width;i++){
for(int j=0;j<height;j++){
//Return a pointer to a located pixel value.
r = image(i,j,0,0); // First channel RED
g = image(i,j,0,1); // Second channel GREEN
b = image(i,j,0,2); // Third channel BLUE
//PAL and NTSC
//Y = 0.299*R + 0.587*G + 0.114*B
gr1 = round(0.299*((double)r) + 0.587*((double)g) + 0.114*((double)b));
//HDTV
//Y = 0.2126*R + 0.7152*G + 0.0722*B
gr2 = round(0.2126*((double)r) + 0.7152*((double)g) + 0.0722*((double)b));
image(i,j,0,0) = gr1;
//image(i,j,0,0) = gr2;
}
}
cimg does not decompress jpeg images itself, it uses your system jpeg library. If you are using a debian-derivative, for example, you'll need apt-get install libjpeg-turbo8-dev before compiling. Have a look through cimg and make sure it's picking up the headers and linking correctly.

loading Animations with RGBA8888 and RGBA4444 showing no difference in memory usage, platform cocos2D & iOS

plateform -> cocos2D, iOS
Step1: Loading animations from FileName.pvr.ccz(TexturePacker) with ImageFormat="RGBA8888"
Shows memory usage in x-code Instruments 10.0 MB.
Step1: Loading animations from FileName.pvr.ccz(TexturePacker) with ImageFormat="RGBA4444"
Shows memory usage in x-code Instruments 10.0 MB.
Question -> why its not showing any difference in Memory Usage while using lower ImageFormat = "RGBA4444" instead of higher ImageFormat = "RGBA8888"?
TexturePacker file size = 2047 * 1348
The default texture format is RGBA8888 so if you have a RGBA4444 texture you need to change the format before loading the texture (and perhaps change it back afterwards).
The method to change texture format for newly created textures is a class method of CCTexture2D:
+ (void) setDefaultAlphaPixelFormat:(CCTexture2DPixelFormat)format;
I found this error cause my memory size same in both format:-http://www.cocos2d-iphone.org/forum/topic/31092.
In CCTexturePVR.m ->
// Not word aligned ?
if( mod != 0 ) {
NSUInteger neededBytes = (4 - mod ) / (bpp/8);
printf("\n");
NSLog(#"cocos2d: WARNING. Current texture size=(%tu,%tu). Convert it to size=(%tu,%tu) in order to save memory", _width, _height, _width + neededBytes, _height );
NSLog(#"cocos2d: WARNING: File: %#", [path lastPathComponent] );
NSLog(#"cocos2d: WARNING: For further info visit: http://www.cocos2d-iphone.org/forum/topic/31092");
printf("\n");
}
its cocos2d or iOS bug which can be handle by adjusting pvr.ccz size
Size dimension should be divisible by 4 but not the Power Of two. it will resolve bug and get expected memory difference for Both Format

Tesseract has crashed

I am using tesseract on my iOS device and it was working properly until recently it started to crash on me. I have been testing with the same image over and over again and prior to now I had it working about 75 times consecutively. The only thing I can think of is that I deleted the app from my iOS device and then ran it again through Xcode.
I am far from an expert on tesseract and I could really use some advice on what to do next, it would truly be a disappointment for all the hours I put in to go to waste because I cannot read the image anymore. Thank you
This is the crash error it appears to happen when the tesseract file in this method
- (BOOL)recognize
{
int returnCode = _tesseract->Recognize(NULL);// here is where the arrow points on the crash
return (returnCode == 0) ? YES : NO;
}
This is an old question from Alex G and I don't see any answer.
Does anyone find the root cause and solution? Please advice. Many thanks.
I hope you are using AVCaptureSession to take continuously photo and passing to tesseract after some image processing.
So before passing UIImage to tesseract for recognising you should check with this:
CGSize size = [image size];//your image
int width = size.width;
int height = size.height;
if (width < 100 || height < 50) {//UIImage must contain some some size
//Consider as invalid image
return;
}
//This condition is not mandatory.
uint32_t* _pixels = (uint32_t *) malloc(width * height * sizeof(uint32_t));
if (!_pixels) {
return;
//Consider as invalid image
}

How to set camera FPS in OpenCV? CV_CAP_PROP_FPS is a fake

How to set Camera FPS?
May be
cvSetCaptureProperty(cameraCapture, CV_CAP_PROP_FPS, 30);
?
But it's return
HIGHGUI ERROR: V4L2: Unable to get property (5) - Invalid argument
Because there is no implementation in highgui/cap_v4l.cpp
static int icvSetPropertyCAM_V4L( CvCaptureCAM_V4L* capture,
int property_id, double value ){
static int width = 0, height = 0;
int retval;
/* initialization */
retval = 0;
/* two subsequent calls setting WIDTH and HEIGHT will change
the video size */
/* the first one will return an error, though. */
switch (property_id) {
case CV_CAP_PROP_FRAME_WIDTH:
width = cvRound(value);
if(width !=0 && height != 0) {
retval = icvSetVideoSize( capture, width, height);
width = height = 0;
}
break;
case CV_CAP_PROP_FRAME_HEIGHT:
height = cvRound(value);
if(width !=0 && height != 0) {
retval = icvSetVideoSize( capture, width, height);
width = height = 0;
}
break;
case CV_CAP_PROP_BRIGHTNESS:
case CV_CAP_PROP_CONTRAST:
case CV_CAP_PROP_SATURATION:
case CV_CAP_PROP_HUE:
case CV_CAP_PROP_GAIN:
case CV_CAP_PROP_EXPOSURE:
retval = icvSetControl(capture, property_id, value);
break;
default:
fprintf(stderr,
"HIGHGUI ERROR: V4L: setting property #%d is not supported\n",
property_id);
}
/* return the the status */
return retval;
}
How to solve it?
using the python wrappers for opencv, it worked for me to refer to the variable as:
cap = cv2.VideoCapture(1)
cap.set(cv2.cv.CV_CAP_PROP_FPS, 60)
I am using python 2.7.3 and opencv 2.4.8
The camera is the PS3 Eye
I don't know if that's still valid, but some time ago, something like one year and a half, I encountered that exactly problem. I contacted with a developer of OpenCV and he told me that the access and ability to change some of the properties of a capture weren't implemented yet and some other just worked for certain kinds of camera. I finally took a look to libdc1394 (working in linux) and made some functions that converted the data retrieved by libdc1394 to IplImages from OpenCV. It wasn't a such a tough task.
CV_CAP_PROP_FPS is a NOT a fake. See cap_libv4l.cpp(1) in OpenCV github repo. The key is to make sure, you use libv4l over v4l while configuring OpenCV. For that, before running cmake, install libv4l-dev
sudo apt-get install libv4l-dev
Now while configuring OpenCV with cmake, enable option, WITH_LIBV4L. If all goes good, in configuration status, you will see some thing similar to below
V4L/V4L2: Using libv4l1 (ver ) / libv4l2 (ver )
And then while building your OpenCV code, you will have to link with libv4l1/libv4l2/libv4lconvert.
Arbitary FPS values at the resolutions you choose, needn't be supported by your webcam. You may check supported resolutions/fps with a graphical tools like cheese or commands like lsusb (2)
check opencv2.4 handbook out, the video capture thing is much better than before,
->set(CV_CAP_PROP_FPS,30);works for me most of the times.
but a little bit low efficiency.
just in case you might not like the new opencv2.4 and still want to control your camera. check the videoinput lib here. it works good and using directshow features.
http://www.aishack.in/2010/03/capturing-images-with-directx/
http://www.muonics.net/school/spring05/videoInput/

mouse handler in opencv for large images, wrong x,y coordinates?

i am using images that are 2048 x 500 and when I use cvShowImage, I only see half the image. This is not a big deal because the interesting part is on the top half of the image. Now, when I use the mouseHandler to get the x,y coordinates of my clicks, I noticed that the coordinate for y (the dimension that doesnt fit in the screen) is wrong.
It seems OpenCV think this is the whole image and recalibrates the coordinate system although we are only effectively showing half the image.
I would need to know how to do 2 things:
- display a resized image that would fit in the screen
get the proper coordinate.
Did anybody encounter similar problems?
Thanks!
Update: it seems the y coordinate is divided by 2 of what it is supposed to be
code:
EXPORT void click_rect(uchar * the_img, int size_x, int size_y, int * points)
{
CvSize size;
size.height = size_y ;
size.width = size_x;
IplImage * img;
img = cvCreateImageHeader(size, IPL_DEPTH_8U, 1);
img->imageData = (char *)the_img;
img->imageDataOrigin = img->imageData;
img1 = cvCreateImage(cvSize((int)((size.width)) , (int)((size.height)) ),IPL_DEPTH_8U, 1);
cvNamedWindow("mainWin",CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
cvSetMouseCallback( "mainWin", mouseHandler_rect, NULL );
cvShowImage("mainWin", img1 );
//// wait for a key
cvWaitKey(0);
points[0] = x_1;
points[1] = x_2;
points[2] = y_1;
points[3] = y_2;
//// release the image
cvDestroyWindow("mainWin");
cvReleaseImage(&img1 );
cvReleaseImage(&img);
}
You should create a window with the CV_WINDOW_KEEPRATIO flag instead of the CV_WINDOW_AUTOSIZE flag. This temporarily fixes the problem with your y values being wrong.
I use OpenCV2.1 and visual studio C++ compiler. I fix this problem with another flag CV_WINDOW_NORMAL and work properly and returns correct coordinates, this flag enables you to resize the image window.
cvNamedWindow("Box Example", CV_WINDOW_NORMAL);
I am having the same problem with OpenCV 2.1 using it with Windows and mingw compiler. It took me forever to find out what was wrong. As you describe it, cvSetMouseCallback gets too large y coordinates. This is apparently due to the image and the cvNamedWindow it is shown in being bigger than my screen resolution; thus I cannot see the bottom of the image.
As a solution I resize the images to a fixed size, such that they fit on the screen (in this case with resolution 800x600, which can be any other values:
// g_input_image, g_output_image and g_resized_image are global IplImage* pointers.
int img_w = cvGetSize(g_input_image).width;
int img_h = cvGetSize(g_input_image).height;
// If the height/width ratio is greater than 6/8 resize height to 600.
if (img_h > (img_w*6)/8) {
g_resized_image = cvCreateImage(cvSize((img_w*600)/img_h, 600), 8, 3);
}
// else adjust width to 800.
else {
g_resized_image = cvCreateImage(cvSize(800, (img_h*800)/img_w), 8, 3);
}
cvResize(g_output_image, g_resized_image);
Not a perfect solution, but works for me...
Cheers,
Linus
How are you building the window? You are not passing CV_WINDOW_AUTOSIZE to cvNamedWindow(), are you?
Share some source, #Denis.

Resources