I'm using FFmpegFrameRecorder to get the video input from my webcam and record it into a video file. The problem is that I'm building my application using a few different demo source codes that I found and I use properties some of which are not completely clear to me.
First, here is my code snippet :
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(FILENAME, grabber.getImageWidth(),grabber.getImageHeight());
recorder.setVideoCodec(13);
recorder.setFormat("mp4");
recorder.setPixelFormat(avutil.PIX_FMT_YUV420P);
recorder.setFrameRate(30);
recorder.setVideoBitrate(10 * 1024 * 1024);
recorder.start();
setVideoCodec(13) - What is the meaning of this (13) how can I understand what actual codec stands behind any number?
setPixelFormat - Just get this, don't know what it's doing in general
setFrameRate(30) - I think this should be pretty clear but still what is the logic behind what frame rate we choose (isn't the high the better?)
setVideoBitrate(10*1024*1024) - again almost no idea what this does and what's the logic behind the numbers?
At the end I just want to mention one last problem that I get recording video like this. If the actual length of the video is let's say 20secs. When I play the video file created from the program it runs significantly faster. Can't tell if it's exactly 2 times faster than it should be but in general if I record a 20sec video then it's played for about 10secs. What may cause this and how can I fix it?
VideoCodec can be chosen from this list found in avcodec.h/avcodec.java (As you can see, the number 13 gets us MPEG4, and there are others, but FFmpeg doesn't have an encoder for all of them):
AV_CODEC_ID_MPEG1VIDEO = 1,
/** preferred ID for MPEG-1/2 video decoding */
AV_CODEC_ID_MPEG2VIDEO = 2,
AV_CODEC_ID_MPEG2VIDEO_XVMC = 3,
AV_CODEC_ID_H261 = 4,
AV_CODEC_ID_H263 = 5,
AV_CODEC_ID_RV10 = 6,
AV_CODEC_ID_RV20 = 7,
AV_CODEC_ID_MJPEG = 8,
AV_CODEC_ID_MJPEGB = 9,
AV_CODEC_ID_LJPEG = 10,
AV_CODEC_ID_SP5X = 11,
AV_CODEC_ID_JPEGLS = 12,
AV_CODEC_ID_MPEG4 = 13,
AV_CODEC_ID_RAWVIDEO = 14,
AV_CODEC_ID_MSMPEG4V1 = 15,
AV_CODEC_ID_MSMPEG4V2 = 16,
AV_CODEC_ID_MSMPEG4V3 = 17,
AV_CODEC_ID_WMV1 = 18,
AV_CODEC_ID_WMV2 = 19,
AV_CODEC_ID_H263P = 20,
AV_CODEC_ID_H263I = 21,
AV_CODEC_ID_FLV1 = 22,
AV_CODEC_ID_SVQ1 = 23,
AV_CODEC_ID_SVQ3 = 24,
AV_CODEC_ID_DVVIDEO = 25,
AV_CODEC_ID_HUFFYUV = 26,
AV_CODEC_ID_CYUV = 27,
AV_CODEC_ID_H264 = 28,
AV_CODEC_ID_INDEO3 = 29,
AV_CODEC_ID_VP3 = 30,
AV_CODEC_ID_THEORA = 31,
AV_CODEC_ID_ASV1 = 32,
AV_CODEC_ID_ASV2 = 33,
AV_CODEC_ID_FFV1 = 34,
AV_CODEC_ID_4XM = 35,
AV_CODEC_ID_VCR1 = 36,
AV_CODEC_ID_CLJR = 37,
AV_CODEC_ID_MDEC = 38,
AV_CODEC_ID_ROQ = 39,
AV_CODEC_ID_INTERPLAY_VIDEO = 40,
AV_CODEC_ID_XAN_WC3 = 41,
AV_CODEC_ID_XAN_WC4 = 42,
AV_CODEC_ID_RPZA = 43,
AV_CODEC_ID_CINEPAK = 44,
AV_CODEC_ID_WS_VQA = 45,
AV_CODEC_ID_MSRLE = 46,
AV_CODEC_ID_MSVIDEO1 = 47,
AV_CODEC_ID_IDCIN = 48,
AV_CODEC_ID_8BPS = 49,
AV_CODEC_ID_SMC = 50,
AV_CODEC_ID_FLIC = 51,
AV_CODEC_ID_TRUEMOTION1 = 52,
AV_CODEC_ID_VMDVIDEO = 53,
AV_CODEC_ID_MSZH = 54,
AV_CODEC_ID_ZLIB = 55,
AV_CODEC_ID_QTRLE = 56,
AV_CODEC_ID_TSCC = 57,
AV_CODEC_ID_ULTI = 58,
AV_CODEC_ID_QDRAW = 59,
AV_CODEC_ID_VIXL = 60,
AV_CODEC_ID_QPEG = 61,
AV_CODEC_ID_PNG = 62,
AV_CODEC_ID_PPM = 63,
AV_CODEC_ID_PBM = 64,
AV_CODEC_ID_PGM = 65,
AV_CODEC_ID_PGMYUV = 66,
AV_CODEC_ID_PAM = 67,
AV_CODEC_ID_FFVHUFF = 68,
AV_CODEC_ID_RV30 = 69,
AV_CODEC_ID_RV40 = 70,
AV_CODEC_ID_VC1 = 71,
AV_CODEC_ID_WMV3 = 72,
AV_CODEC_ID_LOCO = 73,
AV_CODEC_ID_WNV1 = 74,
AV_CODEC_ID_AASC = 75,
AV_CODEC_ID_INDEO2 = 76,
AV_CODEC_ID_FRAPS = 77,
AV_CODEC_ID_TRUEMOTION2 = 78,
AV_CODEC_ID_BMP = 79,
AV_CODEC_ID_CSCD = 80,
AV_CODEC_ID_MMVIDEO = 81,
AV_CODEC_ID_ZMBV = 82,
AV_CODEC_ID_AVS = 83,
AV_CODEC_ID_SMACKVIDEO = 84,
AV_CODEC_ID_NUV = 85,
AV_CODEC_ID_KMVC = 86,
AV_CODEC_ID_FLASHSV = 87,
AV_CODEC_ID_CAVS = 88,
AV_CODEC_ID_JPEG2000 = 89,
AV_CODEC_ID_VMNC = 90,
AV_CODEC_ID_VP5 = 91,
AV_CODEC_ID_VP6 = 92,
AV_CODEC_ID_VP6F = 93,
AV_CODEC_ID_TARGA = 94,
AV_CODEC_ID_DSICINVIDEO = 95,
AV_CODEC_ID_TIERTEXSEQVIDEO = 96,
AV_CODEC_ID_TIFF = 97,
AV_CODEC_ID_GIF = 98,
AV_CODEC_ID_DXA = 99,
AV_CODEC_ID_DNXHD = 100,
AV_CODEC_ID_THP = 101,
AV_CODEC_ID_SGI = 102,
AV_CODEC_ID_C93 = 103,
AV_CODEC_ID_BETHSOFTVID = 104,
AV_CODEC_ID_PTX = 105,
AV_CODEC_ID_TXD = 106,
AV_CODEC_ID_VP6A = 107,
AV_CODEC_ID_AMV = 108,
AV_CODEC_ID_VB = 109,
AV_CODEC_ID_PCX = 110,
AV_CODEC_ID_SUNRAST = 111,
AV_CODEC_ID_INDEO4 = 112,
AV_CODEC_ID_INDEO5 = 113,
AV_CODEC_ID_MIMIC = 114,
AV_CODEC_ID_RL2 = 115,
AV_CODEC_ID_ESCAPE124 = 116,
AV_CODEC_ID_DIRAC = 117,
AV_CODEC_ID_BFI = 118,
AV_CODEC_ID_CMV = 119,
AV_CODEC_ID_MOTIONPIXELS = 120,
AV_CODEC_ID_TGV = 121,
AV_CODEC_ID_TGQ = 122,
AV_CODEC_ID_TQI = 123,
AV_CODEC_ID_AURA = 124,
AV_CODEC_ID_AURA2 = 125,
AV_CODEC_ID_V210X = 126,
AV_CODEC_ID_TMV = 127,
AV_CODEC_ID_V210 = 128,
AV_CODEC_ID_DPX = 129,
AV_CODEC_ID_MAD = 130,
AV_CODEC_ID_FRWU = 131,
AV_CODEC_ID_FLASHSV2 = 132,
AV_CODEC_ID_CDGRAPHICS = 133,
AV_CODEC_ID_R210 = 134,
AV_CODEC_ID_ANM = 135,
AV_CODEC_ID_BINKVIDEO = 136,
AV_CODEC_ID_IFF_ILBM = 137,
AV_CODEC_ID_IFF_BYTERUN1 = 138,
AV_CODEC_ID_KGV1 = 139,
AV_CODEC_ID_YOP = 140,
AV_CODEC_ID_VP8 = 141,
AV_CODEC_ID_PICTOR = 142,
AV_CODEC_ID_ANSI = 143,
AV_CODEC_ID_A64_MULTI = 144,
AV_CODEC_ID_A64_MULTI5 = 145,
AV_CODEC_ID_R10K = 146,
AV_CODEC_ID_MXPEG = 147,
AV_CODEC_ID_LAGARITH = 148,
AV_CODEC_ID_PRORES = 149,
AV_CODEC_ID_JV = 150,
AV_CODEC_ID_DFA = 151,
AV_CODEC_ID_WMV3IMAGE = 152,
AV_CODEC_ID_VC1IMAGE = 153,
AV_CODEC_ID_UTVIDEO = 154,
AV_CODEC_ID_BMV_VIDEO = 155,
AV_CODEC_ID_VBLE = 156,
AV_CODEC_ID_DXTORY = 157,
AV_CODEC_ID_V410 = 158,
AV_CODEC_ID_XWD = 159,
AV_CODEC_ID_CDXL = 160,
AV_CODEC_ID_XBM = 161,
AV_CODEC_ID_ZEROCODEC = 162,
AV_CODEC_ID_MSS1 = 163,
AV_CODEC_ID_MSA1 = 164,
AV_CODEC_ID_TSCC2 = 165,
AV_CODEC_ID_MTS2 = 166,
AV_CODEC_ID_CLLC = 167,
AV_CODEC_ID_MSS2 = 168,
AV_CODEC_ID_VP9 = 169,
AV_CODEC_ID_AIC = 170,
// etc
PixelFormat can be selected from this list in pixfmt.h/avutil.java, but each codec only supports a few of them (most of them support at least AV_PIX_FMT_YUV420P):
/** planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples) */
AV_PIX_FMT_YUV420P = 0,
/** packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr */
AV_PIX_FMT_YUYV422 = 1,
/** packed RGB 8:8:8, 24bpp, RGBRGB... */
AV_PIX_FMT_RGB24 = 2,
/** packed RGB 8:8:8, 24bpp, BGRBGR... */
AV_PIX_FMT_BGR24 = 3,
/** planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples) */
AV_PIX_FMT_YUV422P = 4,
/** planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples) */
AV_PIX_FMT_YUV444P = 5,
/** planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples) */
AV_PIX_FMT_YUV410P = 6,
/** planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) */
AV_PIX_FMT_YUV411P = 7,
/** Y , 8bpp */
AV_PIX_FMT_GRAY8 = 8,
/** Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb */
AV_PIX_FMT_MONOWHITE = 9,
/** Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb */
AV_PIX_FMT_MONOBLACK = 10,
/** 8 bit with PIX_FMT_RGB32 palette */
AV_PIX_FMT_PAL8 = 11,
/** planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_range */
AV_PIX_FMT_YUVJ420P = 12,
/** planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_range */
AV_PIX_FMT_YUVJ422P = 13,
/** planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_range */
AV_PIX_FMT_YUVJ444P = 14,
/** XVideo Motion Acceleration via common packet passing */
AV_PIX_FMT_XVMC_MPEG2_MC = 15,
AV_PIX_FMT_XVMC_MPEG2_IDCT = 16;
/** packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1 */
AV_PIX_FMT_UYVY422 = 17,
/** packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3 */
AV_PIX_FMT_UYYVYY411 = 18,
/** packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb) */
AV_PIX_FMT_BGR8 = 19,
/** packed RGB 1:2:1 bitstream, 4bpp, (msb)1B 2G 1R(lsb), a byte contains two pixels, the first pixel in the byte is the one composed by the 4 msb bits */
AV_PIX_FMT_BGR4 = 20,
/** packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb) */
AV_PIX_FMT_BGR4_BYTE = 21,
/** packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb) */
AV_PIX_FMT_RGB8 = 22,
/** packed RGB 1:2:1 bitstream, 4bpp, (msb)1R 2G 1B(lsb), a byte contains two pixels, the first pixel in the byte is the one composed by the 4 msb bits */
AV_PIX_FMT_RGB4 = 23,
/** packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb) */
AV_PIX_FMT_RGB4_BYTE = 24,
/** planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (first byte U and the following byte V) */
AV_PIX_FMT_NV12 = 25,
/** as above, but U and V bytes are swapped */
AV_PIX_FMT_NV21 = 26,
/** packed ARGB 8:8:8:8, 32bpp, ARGBARGB... */
AV_PIX_FMT_ARGB = 27,
/** packed RGBA 8:8:8:8, 32bpp, RGBARGBA... */
AV_PIX_FMT_RGBA = 28,
/** packed ABGR 8:8:8:8, 32bpp, ABGRABGR... */
AV_PIX_FMT_ABGR = 29,
/** packed BGRA 8:8:8:8, 32bpp, BGRABGRA... */
AV_PIX_FMT_BGRA = 30,
/** Y , 16bpp, big-endian */
AV_PIX_FMT_GRAY16BE = 31,
/** Y , 16bpp, little-endian */
AV_PIX_FMT_GRAY16LE = 32,
/** planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples) */
AV_PIX_FMT_YUV440P = 33,
/** planar YUV 4:4:0 full scale (JPEG), deprecated in favor of PIX_FMT_YUV440P and setting color_range */
AV_PIX_FMT_YUVJ440P = 34,
/** planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples) */
AV_PIX_FMT_YUVA420P = 35,
/** H.264 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers */
AV_PIX_FMT_VDPAU_H264 = 36,
/** MPEG-1 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers */
AV_PIX_FMT_VDPAU_MPEG1 = 37,
/** MPEG-2 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers */
AV_PIX_FMT_VDPAU_MPEG2 = 38,
/** WMV3 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers */
AV_PIX_FMT_VDPAU_WMV3 = 39,
/** VC-1 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers */
AV_PIX_FMT_VDPAU_VC1 = 40,
/** packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big-endian */
AV_PIX_FMT_RGB48BE = 41,
/** packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as little-endian */
AV_PIX_FMT_RGB48LE = 42,
/** packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian */
AV_PIX_FMT_RGB565BE = 43,
/** packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian */
AV_PIX_FMT_RGB565LE = 44,
/** packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), big-endian, most significant bit to 0 */
AV_PIX_FMT_RGB555BE = 45,
/** packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), little-endian, most significant bit to 0 */
AV_PIX_FMT_RGB555LE = 46,
/** packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), big-endian */
AV_PIX_FMT_BGR565BE = 47,
/** packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), little-endian */
AV_PIX_FMT_BGR565LE = 48,
/** packed BGR 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), big-endian, most significant bit to 1 */
AV_PIX_FMT_BGR555BE = 49,
/** packed BGR 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), little-endian, most significant bit to 1 */
AV_PIX_FMT_BGR555LE = 50,
/** HW acceleration through VA API at motion compensation entry-point, Picture.data[3] contains a vaapi_render_state struct which contains macroblocks as well as various fields extracted from headers */
AV_PIX_FMT_VAAPI_MOCO = 51,
/** HW acceleration through VA API at IDCT entry-point, Picture.data[3] contains a vaapi_render_state struct which contains fields extracted from headers */
AV_PIX_FMT_VAAPI_IDCT = 52,
/** HW decoding through VA API, Picture.data[3] contains a vaapi_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers */
AV_PIX_FMT_VAAPI_VLD = 53,
/** planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian */
AV_PIX_FMT_YUV420P16LE = 54,
/** planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian */
AV_PIX_FMT_YUV420P16BE = 55,
/** planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian */
AV_PIX_FMT_YUV422P16LE = 56,
/** planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian */
AV_PIX_FMT_YUV422P16BE = 57,
/** planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian */
AV_PIX_FMT_YUV444P16LE = 58,
/** planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian */
AV_PIX_FMT_YUV444P16BE = 59,
/** MPEG4 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers */
AV_PIX_FMT_VDPAU_MPEG4 = 60,
/** HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer */
AV_PIX_FMT_DXVA2_VLD = 61,
/** packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), little-endian, most significant bits to 0 */
AV_PIX_FMT_RGB444LE = 62,
/** packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), big-endian, most significant bits to 0 */
AV_PIX_FMT_RGB444BE = 63,
/** packed BGR 4:4:4, 16bpp, (msb)4A 4B 4G 4R(lsb), little-endian, most significant bits to 1 */
AV_PIX_FMT_BGR444LE = 64,
/** packed BGR 4:4:4, 16bpp, (msb)4A 4B 4G 4R(lsb), big-endian, most significant bits to 1 */
AV_PIX_FMT_BGR444BE = 65,
/** 8bit gray, 8bit alpha */
AV_PIX_FMT_YA8 = 66,
// etc
FrameRate indicates the number of frames per second the video should be played back at (it has nothing to do with the number or the timing of images you actually record, although it provides a basis for the encoding bitrate). So, in the case of 30 FPS, to cover 20 seconds of video, you need to call record() 30 * 20 = 600 times. If you do no call record() 600 times, then this is the cause of your problem.
VideoBitrate provides the video bitrate (in bits per second) at which the video stream should be encoded at. Wikipedia has a nice article about that.
Related
I was analyzing the code for Arrays.sort() method in java . My question is for what values of integer array a[] will this code return true ?
if (less < e1 && e5 < great)
After Sorting left and right parts recursively, excluding known pivots for what value of array a[] will the center part become too large (comprises > 4/7 of the array) ?
Given QUICKSORT_THRESHOLD = 286 .
Array size cannot be more than 286
Any example of int array please .
It happens when all candidates for pivots are close to either the maximum or the minimum value of the array.
java.util.DualPivotQuicksort#sort() chooses the pivots from 5 positions in the array:
int seventh = (length >> 3) + (length >> 6) + 1;
int e3 = (left + right) >>> 1; // The midpoint
int e2 = e3 - seventh;
int e1 = e2 - seventh;
int e4 = e3 + seventh;
int e5 = e4 + seventh;
So, in order to construct an array that satisfies the condition, we need to fill those 5 positions with extreme values. For example:
int[] x = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, /* e1 = 10 */
0, 0, 0, 0, 0, 0, -1, /* e2 = 17 */
0, 0, 0, 0, 0, 0, 0, /* e3 = 24 */
0, 0, 0, 0, 0, 0, 1, /* e4 = 31 */
0, 0, 0, 0, 0, 0, 2, /* e5 = 38 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
Arrays.sort(x);
And a non-trivial case where the method changes the boundaries of the central part before sorting it:
int[] x = {
70, 66, 11, 24, 10, 28, 58, 13, 19, 90, 15,
79, 16, 69, 39, 14, 10, 16,
40, 59, 47, 77, 90, 50, 50,
50, 16, 76, 86, 70, 33, 90,
24, 35, 73, 93, 87, 19, 91,
73, 87, 22, 15, 24, 92, 34, 35, 98, 11, 40
};
I wish to read image description text from the image property tab (right click) with c++ or python.
Is there anyway to do it?
Looks like Opencv is not supporting it, I guess.
BTW, my OS is ubuntu 16.04.
Thanks,
If you are on Ubuntu, you probably have ImageMagick installed and that has a program called identify within the suite. You can just run the following in a Terminal at the command-line, or you could run a Python subprocess and grab its output:
identify -verbose someImage.jpg
Sample Output
Image: /Users/mark/Desktop/IMG_2326.JPG
Format: JPEG (Joint Photographic Experts Group JFIF format)
Mime type: image/jpeg
Class: DirectClass
Geometry: 3264x2448+0+0
Resolution: 72x72
Print size: 45.3333x34
Units: PixelsPerInch
Type: TrueColor
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:
Red: 8-bit
Green: 8-bit
Blue: 8-bit
Channel statistics:
Pixels: 7990272
Red:
min: 0 (0)
max: 255 (1)
mean: 139.125 (0.545587)
standard deviation: 62.0934 (0.243503)
kurtosis: -0.948773
skewness: -0.255567
entropy: 0.980761
Green:
min: 0 (0)
max: 255 (1)
mean: 129.827 (0.509124)
standard deviation: 63.4802 (0.248942)
kurtosis: -0.744472
skewness: -0.322559
entropy: 0.978628
Blue:
min: 0 (0)
max: 255 (1)
mean: 121.768 (0.477522)
standard deviation: 63.6425 (0.249578)
kurtosis: -1.14208
skewness: 0.0243162
entropy: 0.980614
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 130.24 (0.510744)
standard deviation: 63.4733 (0.248915)
kurtosis: -0.968273
skewness: -0.18575
entropy: 0.980001
Rendering intent: Perceptual
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Matte color: grey74
Background color: white
Border color: srgb(223,223,223)
Transparent color: none
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 3264x2448+0+0
Dispose: Undefined
Iterations: 0
Compression: JPEG
Quality: 96
Orientation: TopLeft
Properties:
date:create: 2017-05-31T13:53:16+01:00
date:modify: 2014-09-23T08:22:25+01:00
exif:ApertureValue: 4845/1918
exif:BrightnessValue: 6155/1061
exif:ColorSpace: 1
exif:ComponentsConfiguration: 1, 2, 3, 0
exif:DateTime: 2014:09:23 08:22:25
exif:DateTimeDigitized: 2014:09:23 08:22:25
exif:DateTimeOriginal: 2014:09:23 08:22:25
exif:ExifImageLength: 2448
exif:ExifImageWidth: 3264
exif:ExifOffset: 204
exif:ExifVersion: 48, 50, 50, 49
exif:ExposureMode: 0
exif:ExposureProgram: 2
exif:ExposureTime: 1/120
exif:Flash: 24
exif:FlashPixVersion: 48, 49, 48, 48
exif:FNumber: 12/5
exif:FocalLength: 103/25
exif:FocalLengthIn35mmFilm: 33
exif:GPSAltitude: 10003/299
exif:GPSAltitudeRef: 0
exif:GPSInfo: 946
exif:GPSLatitude: 51/1, 51/1, 347/100
exif:GPSLatitudeRef: N
exif:GPSLongitude: 2/1, 12/1, 1992/100
exif:GPSLongitudeRef: W
exif:GPSTimeStamp: 7/1, 22/1, 2456/100
exif:ISOSpeedRatings: 64
exif:Make: Apple
exif:MakerNote: 65, 112, 112, 108, 101, 32, 105, 79, 83, 0, 0, 1, 77, 77, 0, 6, 0, 1, 0, 9, 0, 0, 0, 1, 0, 0, 0, 0, 0, 3, 0, 7, 0, 0, 0, 104, 0, 0, 0, 92, 0, 4, 0, 9, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5, 0, 9, 0, 0, 0, 1, 0, 0, 0, 208, 0, 6, 0, 9, 0, 0, 0, 1, 0, 0, 0, 218, 0, 7, 0, 9, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 98, 112, 108, 105, 115, 116, 48, 48, 212, 1, 2, 3, 4, 5, 6, 7, 8, 89, 116, 105, 109, 101, 115, 99, 97, 108, 101, 85, 101, 112, 111, 99, 104, 85, 118, 97, 108, 117, 101, 85, 102, 108, 97, 103, 115, 18, 59, 154, 202, 0, 16, 0, 19, 0, 0, 18, 143, 64, 67, 109, 189, 16, 1, 8, 17, 27, 33, 39, 45, 50, 52, 61, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 63
exif:MeteringMode: 5
exif:Model: iPhone 5
exif:Orientation: 1
exif:ResolutionUnit: 2
exif:SceneCaptureType: 0
exif:SceneType: 1
exif:SensingMethod: 2
exif:ShutterSpeedValue: 5567/806
exif:Software: 7.1.2
exif:SubjectArea: 1631, 1223, 1795, 1077
exif:SubSecTimeDigitized: 918
exif:SubSecTimeOriginal: 918
exif:thumbnail:Compression: 6
exif:thumbnail:JPEGInterchangeFormat: 1210
exif:thumbnail:JPEGInterchangeFormatLength: 12195
exif:thumbnail:ResolutionUnit: 2
exif:thumbnail:XResolution: 72/1
exif:thumbnail:YResolution: 72/1
exif:WhiteBalance: 0
exif:XResolution: 72/1
exif:YCbCrPositioning: 1
exif:YResolution: 72/1
jpeg:colorspace: 2
jpeg:sampling-factor: 2x2,1x1,1x1
signature: 84dc83ac4ff07920155036d321be9b8fe687be8b5eb68a76e20518b3e6f048f8
unknown: 103/25, 103/25, 12/5, 12/5
Profiles:
Profile-exif: 16380 bytes
Artifacts:
verbose: true
Tainted: False
Filesize: 3.9071MiB
Number pixels: 7.99027M
Pixels per second: 47.0016MB
User time: 0.150u
Elapsed time: 0:01.170
Version: ImageMagick 7.0.5-6 Q16 x86_64 2017-05-15 http://www.imagemagick.org
Another option is exiftool, which you run like this at the command-line, and which you could also run as a subprocess in Python:
exiftool ~/Desktop/IMG_2326.JPG
Sample Output
ExifTool Version Number : 10.50
File Name : IMG_2326.JPG
Directory : /Users/mark/Desktop
File Size : 3.9 MB
File Modification Date/Time : 2014:09:23 08:22:25+01:00
File Access Date/Time : 2017:05:31 13:57:20+01:00
File Inode Change Date/Time : 2017:05:31 13:53:16+01:00
File Permissions : rw-------
File Type : JPEG
File Type Extension : jpg
MIME Type : image/jpeg
Exif Byte Order : Big-endian (Motorola, MM)
Make : Apple
Camera Model Name : iPhone 5
Orientation : Horizontal (normal)
X Resolution : 72
Y Resolution : 72
Resolution Unit : inches
Software : 7.1.2
Modify Date : 2014:09:23 08:22:25
Y Cb Cr Positioning : Centered
Exposure Time : 1/120
F Number : 2.4
Exposure Program : Program AE
ISO : 64
Exif Version : 0221
Date/Time Original : 2014:09:23 08:22:25
Create Date : 2014:09:23 08:22:25
Components Configuration : Y, Cb, Cr, -
Shutter Speed Value : 1/120
Aperture Value : 2.4
Brightness Value : 5.801131008
Metering Mode : Multi-segment
Flash : Auto, Did not fire
Focal Length : 4.1 mm
Subject Area : 1631 1223 1795 1077
Run Time Scale : 1000000000
Run Time Epoch : 0
Run Time Value : 20406467784125
Run Time Flags : Valid
Sub Sec Time Original : 918
Sub Sec Time Digitized : 918
Flashpix Version : 0100
Color Space : sRGB
Exif Image Width : 3264
Exif Image Height : 2448
Sensing Method : One-chip color area
Scene Type : Directly photographed
Exposure Mode : Auto
White Balance : Auto
Focal Length In 35mm Format : 33 mm
Scene Capture Type : Standard
Lens Info : 4.12mm f/2.4
Lens Make : Apple
Lens Model : iPhone 5 back camera 4.12mm f/2.4
GPS Latitude Ref : North
GPS Longitude Ref : West
GPS Altitude Ref : Above Sea Level
GPS Time Stamp : 07:22:24.56
Compression : JPEG (old-style)
Thumbnail Offset : 1222
Thumbnail Length : 12195
Image Width : 3264
Image Height : 2448
Encoding Process : Baseline DCT, Huffman coding
Bits Per Sample : 8
Color Components : 3
Y Cb Cr Sub Sampling : YCbCr4:2:0 (2 2)
Aperture : 2.4
GPS Altitude : 33.4 m Above Sea Level
GPS Latitude : 51 deg 51' 3.47" N
GPS Longitude : 2 deg 12' 19.92" W
GPS Position : 51 deg 51' 3.47" N, 2 deg 12' 19.92" W
Image Size : 3264x2448
Megapixels : 8.0
Run Time Since Power Up : 5:40:06
Scale Factor To 35 mm Equivalent: 8.0
Shutter Speed : 1/120
Create Date : 2014:09:23 08:22:25.918
Date/Time Original : 2014:09:23 08:22:25.918
Thumbnail Image : (Binary data 12195 bytes, use -b option to extract)
Circle Of Confusion : 0.004 mm
Field Of View : 57.2 deg
Focal Length : 4.1 mm (35 mm equivalent: 33.0 mm)
Hyperfocal Distance : 1.89 m
Light Value : 10.1
Another option is exiv2 which is available from here and also has various library APIs available.
I have not used it and cannot endorse it, but there is also a Python interface to exiv2.
In case you wanted a hand on Python subprocesses, you do this sort of thing:
import subprocess
...
...
p = subprocess.Popen(['identify -verbose someImage.jpg'], stdout=subprocess.PIPE)
retcode = p.wait()
data = p.stdout.read()
These properties should be stored in Exif data.
In Python, see here for some code to read Exif data.
With Opencv we can able to read image type,width,height,Depth but we cant able to read other parameters related to ISo,ShutterSpeed,Brightness,Description and Date Modified,Created.
If you want to get that information you can get it using C#
I was testing around with OpenCV matrices and the display function and had this bug. It took me more than half a day to reveal it:
I originally tried to display OpenCV matrices regardless of the type of matric e.g. CvMat or Mat, ...
with a display method recommended by Mr vasile from another post of mine Multi channel Mat display function
The display method simply fetches all data of the matrix to cout stream
this is my program:
// First: CV_32FC3 works OK
float objpts[12] = {0, 105, 105, 0, 0, 0, 105, 105, 0, 0, 0, 0};
CvMat objptsmat = cvMat( 1, 4, CV_32FC3, objpts);
CvMat* objectPoints = &objptsmat;
CvMatShow(objectPoints);
getchar();
output:
// Second: CV_64FC3 crashes
float objpts[12] = {0, 105, 105, 0, 0, 0, 105, 105, 0, 0, 0, 0};
CvMat objptsmat = cvMat( 1, 4, CV_64FC3, objpts);
CvMat* objectPoints = &objptsmat;
CvMatShow(objectPoints);
getchar();
output:
they should be both the same. Right??!!
In the second example, you should have the array declared as
double objpts[12] = {0, 105, 105, 0, 0, 0, 105, 105, 0, 0, 0, 0};
You can read CV_xxtCn as
xx: number of bits
t: type (F = floating point type, S = signed integer, U = unsigned integer)
n: number of channels
Someone knows an algorithm that gets temperatue in Kelvin/Celsius and returns RGB?
Like in thermal cameras.
I found some links :
http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_T.html
http://www.fourmilab.ch/documents/specrend/specrend.c
But i cant figure what XYZ color is ?
I only have temperature in Celsius..
i can convert it to any temperature Temperature Conversion Formulas
UPDATE:
Blackbody Color Datafile
I have found this.. but those Kelvin degrees are impossible.. i mean
red suppose to be hot.. so why 8000k is blue and 1000k is red...
The best option is to use an image with GetPixel:
private void UpdateTemp()
{
Bitmap temps = (Bitmap)Properties.Resources.temp;
if (curTemp >= 0)
{
int i = curTemp;
if (i < 0)
i = 0;
if (i > temps.Width-1)
i = temps.Width-1;
this.BackColor = temps.GetPixel(i, 10);
}
}
Or building an array. Source
private static Color[] colors =
{
Color.FromArgb(155, 188, 255), // 40000
Color.FromArgb(155, 188, 255), // 39500
Color.FromArgb(155, 188, 255), // 39000
Color.FromArgb(155, 188, 255), // 38500
Color.FromArgb(156, 188, 255), // 38000
Color.FromArgb(156, 188, 255), // 37500
Color.FromArgb(156, 189, 255), // 37000
Color.FromArgb(156, 189, 255), // 36500
Color.FromArgb(156, 189, 255), // 36000
Color.FromArgb(157, 189, 255), // 35500
Color.FromArgb(157, 189, 255), // 35000
Color.FromArgb(157, 189, 255), // 34500
Color.FromArgb(157, 189, 255), // 34000
Color.FromArgb(157, 189, 255), // 33500
Color.FromArgb(158, 190, 255), // 33000
Color.FromArgb(158, 190, 255), // 32500
Color.FromArgb(158, 190, 255), // 32000
Color.FromArgb(158, 190, 255), // 31500
Color.FromArgb(159, 190, 255), // 31000
Color.FromArgb(159, 190, 255), // 30500
Color.FromArgb(159, 191, 255), // 30000
Color.FromArgb(159, 191, 255), // 29500
Color.FromArgb(160, 191, 255), // 29000
Color.FromArgb(160, 191, 255), // 28500
Color.FromArgb(160, 191, 255), // 28000
Color.FromArgb(161, 192, 255), // 27500
Color.FromArgb(161, 192, 255), // 27000
Color.FromArgb(161, 192, 255), // 26500
Color.FromArgb(162, 192, 255), // 26000
Color.FromArgb(162, 193, 255), // 25500
Color.FromArgb(163, 193, 255), // 25000
Color.FromArgb(163, 193, 255), // 24500
Color.FromArgb(163, 194, 255), // 24000
Color.FromArgb(164, 194, 255), // 23500
Color.FromArgb(164, 194, 255), // 23000
Color.FromArgb(165, 195, 255), // 22500
Color.FromArgb(166, 195, 255), // 22000
Color.FromArgb(166, 195, 255), // 21500
Color.FromArgb(167, 196, 255), // 21000
Color.FromArgb(168, 196, 255), // 20500
Color.FromArgb(168, 197, 255), // 20000
Color.FromArgb(169, 197, 255), // 19500
Color.FromArgb(170, 198, 255), // 19000
Color.FromArgb(171, 198, 255), // 18500
Color.FromArgb(172, 199, 255), // 18000
Color.FromArgb(173, 200, 255), // 17500
Color.FromArgb(174, 200, 255), // 17000
Color.FromArgb(175, 201, 255), // 16500
Color.FromArgb(176, 202, 255), // 16000
Color.FromArgb(177, 203, 255), // 15500
Color.FromArgb(179, 204, 255), // 15000
Color.FromArgb(180, 205, 255), // 14500
Color.FromArgb(182, 206, 255), // 14000
Color.FromArgb(184, 207, 255), // 13500
Color.FromArgb(186, 208, 255), // 13000
Color.FromArgb(188, 210, 255), // 12500
Color.FromArgb(191, 211, 255), // 12000
Color.FromArgb(193, 213, 255), // 11500
Color.FromArgb(196, 215, 255), // 11000
Color.FromArgb(200, 217, 255), // 10500
Color.FromArgb(204, 219, 255), // 10000
Color.FromArgb(208, 222, 255), // 9500
Color.FromArgb(214, 225, 255), // 9000
Color.FromArgb(220, 229, 255), // 8500
Color.FromArgb(227, 233, 255), // 8000
Color.FromArgb(235, 238, 255), // 7500
Color.FromArgb(245, 243, 255), // 7000
Color.FromArgb(255, 249, 253), // 6500
Color.FromArgb(255, 243, 239), // 6000
Color.FromArgb(255, 236, 224), // 5500
Color.FromArgb(255, 228, 206), // 5000
Color.FromArgb(255, 219, 186), // 4500
Color.FromArgb(255, 209, 163), // 4000
Color.FromArgb(255, 196, 137), // 3500
Color.FromArgb(255, 180, 107), // 3000
Color.FromArgb(255, 161, 72), // 2500
Color.FromArgb(255, 137, 18), // 2000
Color.FromArgb(255, 109, 0), // 1500
Color.FromArgb(255, 51, 0), // 1000
};
I realize this is a two-year old thread, but I had the same predicament.
I took the data from the color table and did applied piece-wise 5th order polynomial fitting using Numpy.polyfit in Python. From those coefficients I was able to come up with the C# function below. R-squared values for the fits are close to or exceed 0.999. It has less than .01% error through most of its domain, but it does have a couple of points where it is closer to 3%. Should be good enough for most situations though.
private Color blackBodyColor(double temp)
{
float x = (float)(temp / 1000.0);
float x2 = x * x;
float x3 = x2 * x;
float x4 = x3 * x;
float x5 = x4 * x;
float R, G, B = 0f;
// red
if (temp <= 6600)
R = 1f;
else
R = 0.0002889f * x5 - 0.01258f * x4 + 0.2148f * x3 - 1.776f * x2 + 6.907f * x - 8.723f;
// green
if (temp <= 6600)
G = -4.593e-05f * x5 + 0.001424f * x4 - 0.01489f * x3 + 0.0498f * x2 + 0.1669f * x - 0.1653f;
else
G = -1.308e-07f * x5 + 1.745e-05f * x4 - 0.0009116f * x3 + 0.02348f * x2 - 0.3048f * x + 2.159f;
// blue
if (temp <= 2000f)
B = 0f;
else if (temp < 6600f)
B = 1.764e-05f * x5 + 0.0003575f * x4 - 0.01554f * x3 + 0.1549f * x2 - 0.3682f * x + 0.2386f;
else
B = 1f;
return Color.FromScRgb(1f, R, G, B);
}
If get you right you are looking for a theoretical background on XYZ color space
Color temperature is based on the actual color of light emitted from something (theoretically, an "ideal black body") that emits light based solely on its temperature.
Some examples of this kind of light source: if you have an electric stove element that is glowing red, it might be around 1000K. A regular incandescent bulb filament is around 2700K, and the sun is roughly 5700K. All three are fair approximations of a "black body"; they emit a particular spectrum of light based on their actual temperature.
Many artificial light sources are not actually the "temperature" of the light they emit (and their spectra are generally not black-body spectra, either...). Instead, their "temperature" rating is the temperature a theoretical black body would have to be in order to emit light of that color. There are also colors that cannot be generated by a black body: light which is greenish or purplish compared to a more "natural"-looking black body illumination.
As mentioned in one of the comments, the kind of thermal camera displays you are probably thinking about are all false-color. In a false-color display, the colors are chosen for convenience only: so, for a thermal camera they might choose a "hot"-looking red for warm, and "cold"-looking blue for cold. But, they could just as easily choose a range from black to white, or fuschia to green.
Because false-color displays are arbitrary, you really need to check the color key to a particular image or system if you want to estimate the temperature (scientific images should generally have some kind of color key for this purpose). If you have no color key, and no documentation on how the image was generated, you are out of luck.
The above function overestimate red color when temp > 10000 K. Colors turn to purple when temp>14000. I refitted the data with 7th order polynomials. The coefficients of should be:
def temp_to_rgb(temp):
t = temp/1000.
# calculate red
if t < 6.527:
red = 1.0
else:
coeffs = [ 4.93596077e+00, -1.29917429e+00,
1.64810386e-01, -1.16449912e-02,
4.86540872e-04, -1.19453511e-05,
1.59255189e-07, -8.89357601e-10]
tt = min(t,40)
red = poly(coeffs,tt)
red = max(red,0)
red = min(red,1)
# calcuate green
if t < 0.85:
green = 0.0
elif t < 6.6:
coeffs = [ -4.95931720e-01, 1.08442658e+00,
-9.17444217e-01, 4.94501179e-01,
-1.48487675e-01, 2.49910386e-02,
-2.21528530e-03, 8.06118266e-05]
green = poly(coeffs,t)
else:
coeffs = [ 3.06119745e+00, -6.76337896e-01,
8.28276286e-02, -5.72828699e-03,
2.35931130e-04, -5.73391101e-06,
7.58711054e-08, -4.21266737e-10]
tt = min(t,40)
green = poly(coeffs,tt)
green = max(green,0)
green = min(green,1)
# calculate blue
if t < 1.9:
blue = 0.0
elif t < 6.6:
coeffs = [ 4.93997706e-01, -8.59349314e-01,
5.45514949e-01, -1.81694167e-01,
4.16704799e-02, -6.01602324e-03,
4.80731598e-04, -1.61366693e-05]
blue = poly(coeffs,t)
else:
blue = 1.0
blue = max(blue,0)
blue = min(blue,1)
return (red,green,blue)
Here poly(coeffs,x) = coeffs[0] + coeffs[1]*x + coeffs[2]*x**2 + ...
Sorry I am not familiar with C# but you can easily read the codes.
The error is within only 0.5% for most cases and at most 1.2% for red in temp = 6600 K. High order polynomials are adopted here so red and green must keep constant for temp > 40000 K, otherwise strange things will happen.
I am developing image uploader for Flash 10. Is there a way to read jpeg quality of the browsed images.
Unfortunately, it can't be done directly:
The quality factor is not stored
directly in the JPEG file, so you
cannot read the quality factor from
the file. (from: Microsoft support pages...)
In more detail:
The quantization table that was used
to compress an image is stored in
the JFIF header, but the JPEG Quality
Factor that was used to generate the
quantization table is not stored along
with the image and hence the original
JPEG Quality Factor is lost. (from: JPEG Compression Metrics as a Quality Aware Image Transcoding, by Surendar Chandra and Carla Schlatter Ellis)
The above quote is from a paper which discusses ways to estimate the level of compression (by examining the quantization tables used in the image), but it doesn't look easy to implement: there's an example here which is part of the Image Magick codebase, but it's written in C.
Image Magick has been ported to Haxe, which can be complied into Flash code, so conceivably you could get something working, but I'm afraid it's beyond my skills to explain how!
EDIT: just found a similar question on SuperUser, which also mentions Image Magick.
EDIT: you might also be interested in the answers to this question, which asked how to get the size of an image without loading the whole file (good for dealing with images bigger than Flash can handle).
I have used the libjpeg to finish this job, maybe you can refer to my code
#include <stdio.h>
#include <math.h>
#include "jpeglib.h"
#include <setjmp.h>
static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
16, 11, 10, 16, 24, 40, 51, 61,
12, 12, 14, 19, 26, 58, 60, 55,
14, 13, 16, 24, 40, 57, 69, 56,
14, 17, 22, 29, 51, 87, 80, 62,
18, 22, 37, 56, 68, 109, 103, 77,
24, 35, 55, 64, 81, 104, 113, 92,
49, 64, 78, 87, 103, 121, 120, 101,
72, 92, 95, 98, 112, 100, 103, 99
};
int ReadJpegQuality(const char *filename)
{
FILE * infile = fopen(filename, "rb");
fseek(infile,0,SEEK_END);
size_t sz = ftell(infile);
fseek(infile,0,SEEK_SET);
unsigned char* buffer = new unsigned char[sz];
fread(buffer,1,sz,infile);
fclose(infile);
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_mem_src(&cinfo,(unsigned char*)buffer,sz);
jpeg_read_header(&cinfo, TRUE);
int tmp_quality = 0;
int linear_quality = 0;
const int aver_times = 3;
int times = 0;
int aver_quality = 0;
for(int i=0;i<DCTSIZE2;i++)
{
long temp = cinfo.quant_tbl_ptrs[0]->quantval[i];
if(temp<32767L&&temp>0)
{
linear_quality = ceil((float)(temp*100L - 50L)/std_luminance_quant_tbl[i]);
if(linear_quality==1) tmp_quality = 1;
else if(linear_quality==100) tmp_quality = 100;
else if(linear_quality>100)
{
tmp_quality = ceil((float)5000/linear_quality);
}
else
{
tmp_quality = 100 - ceil((float)linear_quality/2);
}
aver_quality += tmp_quality;
if(aver_times==++times)
{
aver_quality /= aver_times;
break;
}
}
}
jpeg_destroy_decompress(&cinfo);
return aver_quality;
}
int main(int argc,char** argv)
{
printf("quality: %d\n",ReadJpegQuality("test1.jpg"));
return 0;
}
this method is using the libjpeg to read jpg file's quantization table,then use the quantization table calculate the quality arguments.