Search Results

Search found 266 results on 11 pages for 'visruth cv'.

Page 5/11 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11  | Next Page >

  • Is there a performance advantage in using a 64bit version of openCV+Emgu instead of 32bit?

    - by Jelly Amma
    Hello, I am developing an application that processes images captured in real time by a Point Grey camera (http://www.ptgrey.com/). The Point Grey SDK is a .net wrapper and can be either 32bit or 64bit. Then to process the captured images, I'm using a wrapper for openCV called Emgu CV (http://www.emgu.com/) that comes in both 32bit or 64bit flavors as well. Now, being on Vista64 I went for the 64bit versions of FlyCapture (Point Grey's SDK) and Emgu CV (which includes openCV in its install) hoping to maximize performance. Recently I've been wanting to call my FlyCapture+Emgu DLL code from XNA, which unfortunately only exists in 32bit, and I realize that I may have to reinstall all those components in 32bit as I don't really want to go through IPC, remoting, etc. Apart from the obvious limit to memory space inherent to 32bit, is there also a performance loss I should be expecting? How dramatic would that be and why ? Thanks in advance for any advice or explanation.

    Read the article

  • OpenCV 2.4.2 on Matlab 2012b (Windows 7)

    - by Maik Xhani
    Hello i am trying to use OpenCV 2.4.2 in Matlab 2012b. I have tried those actions: downloaded OpenCV 2.4.2 used CMake on opencv folder using Visual Studio 10 and Visual Studio 10 Win64 compiler built Debug and Release version with Visual Studio first without any other option and then with D_SCL_SECURE=1 specified for every project changed Matlab's mexopts.bat and adding new lines refering to library and include (see bottom for mexopts.bat content) with Visual Studio 10 compiler tried to compile a simple file with a OpenCV library inclusion and all goes well. try to compile something that actually uses OpenCV commands and get errors. I used openmexopencv library and when tried to compile something i get this error cv.make mex -largeArrayDims -D_SECURE_SCL=1 -Iinclude -I"C:\OpenCV\build\include" -L"C:\OpenCV\build\x64\vc10\lib" -lopencv_calib3d242 -lopencv_contrib242 -lopencv_core242 -lopencv_features2d242 -lopencv_flann242 -lopencv_gpu242 -lopencv_haartraining_engine -lopencv_highgui242 -lopencv_imgproc242 -lopencv_legacy242 -lopencv_ml242 -lopencv_nonfree242 -lopencv_objdetect242 -lopencv_photo242 -lopencv_stitching242 -lopencv_ts242 -lopencv_video242 -lopencv_videostab242 src+cv\CamShift.cpp lib\MxArray.obj -output +cv\CamShift CamShift.cpp C:\Program Files\MATLAB\R2012b\extern\include\tmwtypes.h(821) : warning C4091: 'typedef ': ignorato a sinistra di 'wchar_t' quando non si dichiara alcuna variabile c:\program files\matlab\r2012b\extern\include\matrix.h(319) : error C4430: identificatore di tipo mancante, verr… utilizzato int. Nota: default-int non Š pi— supportato in C++ the content of my mexopts.bat is @echo off rem MSVC100OPTS.BAT rem rem Compile and link options used for building MEX-files rem using the Microsoft Visual C++ compiler version 10.0 rem rem $Revision: 1.1.6.4.2.1 $ $Date: 2012/07/12 13:53:59 $ rem Copyright 2007-2009 The MathWorks, Inc. rem rem StorageVersion: 1.0 rem C++keyFileName: MSVC100OPTS.BAT rem C++keyName: Microsoft Visual C++ 2010 rem C++keyManufacturer: Microsoft rem C++keyVersion: 10.0 rem C++keyLanguage: C++ rem C++keyLinkerName: Microsoft Visual C++ 2010 rem C++keyLinkerVersion: 10.0 rem rem ******************************************************************** rem General parameters rem ******************************************************************** set MATLAB=%MATLAB% set VSINSTALLDIR=c:\Program Files (x86)\Microsoft Visual Studio 10.0 set VCINSTALLDIR=%VSINSTALLDIR%\VC set OPENCVDIR=C:\OpenCV rem In this case, LINKERDIR is being used to specify the location of the SDK set LINKERDIR=c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\ set PATH=%VCINSTALLDIR%\bin\amd64;%VCINSTALLDIR%\bin;%VCINSTALLDIR%\VCPackages;%VSINSTALLDIR%\Common7\IDE;%VSINSTALLDIR%\Common7\Tools;%LINKERDIR%\bin\x64;%LINKERDIR%\bin;%MATLAB_BIN%;%PATH% set INCLUDE=%OPENCVDIR%\build\include;%VCINSTALLDIR%\INCLUDE;%VCINSTALLDIR%\ATLMFC\INCLUDE;%LINKERDIR%\include;%INCLUDE% set LIB=%OPENCVDIR%\build\x64\vc10\lib;%VCINSTALLDIR%\LIB\amd64;%VCINSTALLDIR%\ATLMFC\LIB\amd64;%LINKERDIR%\lib\x64;%MATLAB%\extern\lib\win64;%LIB% set MW_TARGET_ARCH=win64 rem ******************************************************************** rem Compiler parameters rem ******************************************************************** set COMPILER=cl set COMPFLAGS=/c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD set OPTIMFLAGS=/O2 /Oy- /DNDEBUG set DEBUGFLAGS=/Z7 set NAME_OBJECT=/Fo rem ******************************************************************** rem Linker parameters rem ******************************************************************** set LIBLOC=%MATLAB%\extern\lib\win64\microsoft set LINKER=link set LINKFLAGS=/dll /export:%ENTRYPOINT% /LIBPATH:"%LIBLOC%" libmx.lib libmex.lib libmat.lib /MACHINE:X64 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib opencv_calib3d242.lib opencv_contrib242.lib opencv_core242.lib opencv_features2d242.lib opencv_flann242.lib opencv_gpu242.lib opencv_haartraining_engine.lib opencv_imgproc242.lib opencv_highgui242.lib opencv_legacy242.lib opencv_ml242.lib opencv_nonfree242.lib opencv_objdetect242.lib opencv_photo242.lib opencv_stitching242.lib opencv_ts242.lib opencv_video242.lib opencv_videostab242.lib /nologo /manifest /incremental:NO /implib:"%LIB_NAME%.x" /MAP:"%OUTDIR%%MEX_NAME%%MEX_EXT%.map" set LINKOPTIMFLAGS= set LINKDEBUGFLAGS=/debug /PDB:"%OUTDIR%%MEX_NAME%%MEX_EXT%.pdb" set LINK_FILE= set LINK_LIB= set NAME_OUTPUT=/out:"%OUTDIR%%MEX_NAME%%MEX_EXT%" set RSP_FILE_INDICATOR=@ rem ******************************************************************** rem Resource compiler parameters rem ******************************************************************** set RC_COMPILER=rc /fo "%OUTDIR%mexversion.res" set RC_LINKER= set POSTLINK_CMDS=del "%LIB_NAME%.x" "%LIB_NAME%.exp" set POSTLINK_CMDS1=mt -outputresource:"%OUTDIR%%MEX_NAME%%MEX_EXT%;2" -manifest "%OUTDIR%%MEX_NAME%%MEX_EXT%.manifest" set POSTLINK_CMDS2=del "%OUTDIR%%MEX_NAME%%MEX_EXT%.manifest" set POSTLINK_CMDS3=del "%OUTDIR%%MEX_NAME%%MEX_EXT%.map"

    Read the article

  • Resize an array of images with OpenCV

    - by amr
    I'm passing an array of images (IplImage**) to an object in C++ using OpenCV. I'm then trying to iterate over that array and resize them all to a fixed size (150x150) I'm doing it this way: for(int i = 0; i< this->numTrainingFaces; i++) { IplImage* frame_copy = cvCreateImage( cvSize(150,150), this->faceImageArray[0]->depth, this->faceImageArray[0]->nChannels ); cout << "Created image" << endl; cvResize(this->faceImageArray[i], frame_copy); cout << "Resized image" << endl; IplImage* grey_image = cvCreateImage( cvSize( frame_copy->width, frame_copy->height ), IPL_DEPTH_8U, 1 ); cout << "Created grey image" << endl; cvCvtColor( frame_copy, grey_image, CV_RGB2GRAY ); cout << "Converted image" << endl; this->faceImageArray[i] = grey_image; cvReleaseImage(&frame_copy); cvReleaseImage(&grey_image); } But I'm getting this output, and I'm not sure why: Created image Resized image Created grey image Converted image Created image OpenCV Error: Assertion failed (src.type() == dst.type()) in cvResize, file /build/buildd/opencv-2.1.0/src/cv/cvimgwarp.cpp, line 3102 terminate called after throwing an instance of 'cv::Exception' what(): /build/buildd/opencv-2.1.0/src/cv/cvimgwarp.cpp:3102: error: (-215) src.type() == dst.type() in function cvResize Aborted I'm basically just trying to replace the image in the array with the resized one in as few steps as possible. Edit: Revised my code as follows: for(int i = 0; i< this->numTrainingFaces; i++) { IplImage* frame_copy = cvCreateImage( cvSize(150,150), this->faceImageArray[i]->depth, this->faceImageArray[i]->nChannels ); cvResize(this->faceImageArray[i], frame_copy); IplImage* grey_image = cvCreateImage( cvSize( frame_copy->width, frame_copy->height ), IPL_DEPTH_8U, 1 ); cvCvtColor( frame_copy, grey_image, CV_RGB2GRAY ); faceImageArray[i] = cvCreateImage( cvSize(grey_image->width, grey_image->height), grey_image->depth, grey_image->nChannels); cvCopy(grey_image,faceImageArray[i]); cvReleaseImage(&frame_copy); cvReleaseImage(&grey_image); } Then later on I'm performing some PCA, and get this output: OpenCV Error: Null pointer (Null pointer to the written object) in cvWrite, file /build/buildd/opencv-2.1.0/src/cxcore/cxpersistence.cpp, line 4740 But I don't think my code has got to the point where I'm explicitly calling cvWrite, so it must be part of the library. I can give a full implementation if necessary - is there anything in my code that's going to create a null pointer?

    Read the article

  • Unlocking a mutex from a different thread (C++)

    - by dan
    I'm using the C++ boost::thread library, which in my case means I'm using pthreads. Officially, a mutex must be unlocked from the same thread which locks it, and I want the effect of being able to lock in one thread and then unlock in another. There are many ways to accomplish this. One possibility would be to write a new mutex class which allows this behavior. For example: class inter_thread_mutex{ bool locked; boost::mutex mx; boost::condition_variable cv; public: void lock(){ boost::unique_lock<boost::mutex> lck(mx); while(locked) cv.wait(lck); locked=true; } void unlock(){ { boost::lock_guard<boost::mutex> lck(mx); if(!locked) error(); locked=false; } cv.notify_one(); } // bool try_lock(); void error(); etc. } I should point out that the above code doesn't guarantee FIFO access, since if one thread calls lock() while another calls unlock(), this first thread may acquire the lock ahead of other threads which are waiting. (Come to think of it, the boost::thread documentation doesn't appear to make any explicit scheduling guarantees for either mutexes or condition variables). But let's just ignore that (and any other bugs) for now. My question is, if I decide to go this route, would I be able to use such a mutex as a model for the boost Lockable concept. For example, would anything go wrong if I use a boost::unique_lock< inter_thread_mutex for RAII-style access, and then pass this lock to boost::condition_variable_any.wait(), etc. On one hand I don't see why not. On the other hand, "I don't see why not" is usually a very bad way of determining whether something will work. The reason I ask is that if it turns out that I have to write wrapper classes for RAII locks and condition variables and whatever else, then I'd rather just find some other way to achieve the same effect.

    Read the article

  • wamp server not working? or bad php code

    - by lclaud
    I have this PHP code: <?php $username="root"; $password="******";// censored out $database="bazadedate"; mysql_connect("127.0.0.1",$username,$password); // i get unknown constant localhost if used instead of the loopback ip @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM backup"; $result=mysql_query($query); $num=mysql_numrows($result); $i=0; $raspuns=""; while ($i < $num) { $data=mysql_result($result,$i,"data"); $suma=mysql_result($result,$i,"suma"); $cv=mysql_result($result,$i,"cv"); $det=mysql_result($result,$i,"detaliu"); $raspuns = $raspuns."#".$data."#".$suma."#".$cv."#".$det."@"; $i++; } echo "<b> $raspuns </b>"; mysql_close(); ?> And it should return a single string containing all data from the table. But it says "connection reset when loading page". the log is : [Tue Jun 15 16:20:31 2010] [notice] Parent: child process exited with status 255 -- Restarting. [Tue Jun 15 16:20:31 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations [Tue Jun 15 16:20:31 2010] [notice] Server built: Dec 10 2008 00:10:06 [Tue Jun 15 16:20:31 2010] [notice] Parent: Created child process 2336 [Tue Jun 15 16:20:31 2010] [notice] Child 2336: Child process is running [Tue Jun 15 16:20:31 2010] [notice] Child 2336: Acquired the start mutex. [Tue Jun 15 16:20:31 2010] [notice] Child 2336: Starting 64 worker threads. [Tue Jun 15 16:20:31 2010] [notice] Child 2336: Starting thread to listen on port 80. [Tue Jun 15 16:20:35 2010] [notice] Parent: child process exited with status 255 -- Restarting. [Tue Jun 15 16:20:35 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations [Tue Jun 15 16:20:35 2010] [notice] Server built: Dec 10 2008 00:10:06 [Tue Jun 15 16:20:35 2010] [notice] Parent: Created child process 1928 [Tue Jun 15 16:20:35 2010] [notice] Child 1928: Child process is running [Tue Jun 15 16:20:35 2010] [notice] Child 1928: Acquired the start mutex. [Tue Jun 15 16:20:35 2010] [notice] Child 1928: Starting 64 worker threads. [Tue Jun 15 16:20:35 2010] [notice] Child 1928: Starting thread to listen on port 80. Any idea why it outputs nothing?

    Read the article

  • Steganography Experiment - Trouble hiding message bits in DCT coefficients

    - by JohnHankinson
    I have an application requiring me to be able to embed loss-less data into an image. As such I've been experimenting with steganography, specifically via modification of DCT coefficients as the method I select, apart from being loss-less must also be relatively resilient against format conversion, scaling/DSP etc. From the research I've done thus far this method seems to be the best candidate. I've seen a number of papers on the subject which all seem to neglect specific details (some neglect to mention modification of 0 coefficients, or modification of AC coefficient etc). After combining the findings and making a few modifications of my own which include: 1) Using a more quantized version of the DCT matrix to ensure we only modify coefficients that would still be present should the image be JPEG'ed further or processed (I'm using this in place of simply following a zig-zag pattern). 2) I'm modifying bit 4 instead of the LSB and then based on what the original bit value was adjusting the lower bits to minimize the difference. 3) I'm only modifying the blue channel as it should be the least visible. This process must modify the actual image and not the DCT values stored in file (like jsteg) as there is no guarantee the file will be a JPEG, it may also be opened and re-saved at a later stage in a different format. For added robustness I've included the message multiple times and use the bits that occur most often, I had considered using a QR code as the message data or simply applying the reed-solomon error correction, but for this simple application and given that the "message" in question is usually going to be between 10-32 bytes I have plenty of room to repeat it which should provide sufficient redundancy to recover the true bits. No matter what I do I don't seem to be able to recover the bits at the decode stage. I've tried including / excluding various checks (even if it degrades image quality for the time being). I've tried using fixed point vs. double arithmetic, moving the bit to encode, I suspect that the message bits are being lost during the IDCT back to image. Any thoughts or suggestions on how to get this working would be hugely appreciated. (PS I am aware that the actual DCT/IDCT could be optimized from it's naive On4 operation using row column algorithm, or an FDCT like AAN, but for now it just needs to work :) ) Reference Papers: http://www.lokminglui.com/dct.pdf http://arxiv.org/ftp/arxiv/papers/1006/1006.1186.pdf Code for the Encode/Decode process in C# below: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing.Imaging; using System.Drawing; namespace ImageKey { public class Encoder { public const int HIDE_BIT_POS = 3; // use bit position 4 (1 << 3). public const int HIDE_COUNT = 16; // Number of times to repeat the message to avoid error. // JPEG Standard Quantization Matrix. // (to get higher quality multiply by (100-quality)/50 .. // for lower than 50 multiply by 50/quality. Then round to integers and clip to ensure only positive integers. public static double[] Q = {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}; // Maximum qauality quantization matrix (if all 1's doesn't modify coefficients at all). public static double[] Q2 = {1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1}; public static Bitmap Encode(Bitmap b, string key) { Bitmap response = new Bitmap(b.Width, b.Height, PixelFormat.Format32bppArgb); uint imgWidth = ((uint)b.Width) & ~((uint)7); // Maximum usable X resolution (divisible by 8). uint imgHeight = ((uint)b.Height) & ~((uint)7); // Maximum usable Y resolution (divisible by 8). // Start be transferring the unmodified image portions. // As we'll be using slightly less width/height for the encoding process we'll need the edges to be populated. for (int y = 0; y < b.Height; y++) for (int x = 0; x < b.Width; x++) { if( (x >= imgWidth && x < b.Width) || (y>=imgHeight && y < b.Height)) response.SetPixel(x, y, b.GetPixel(x, y)); } // Setup the counters and byte data for the message to encode. StringBuilder sb = new StringBuilder(); for(int i=0;i<HIDE_COUNT;i++) sb.Append(key); byte[] codeBytes = System.Text.Encoding.ASCII.GetBytes(sb.ToString()); int bitofs = 0; // Current bit position we've encoded too. int totalBits = (codeBytes.Length * 8); // Total number of bits to encode. for (int y = 0; y < imgHeight; y += 8) { for (int x = 0; x < imgWidth; x += 8) { int[] redData = GetRedChannelData(b, x, y); int[] greenData = GetGreenChannelData(b, x, y); int[] blueData = GetBlueChannelData(b, x, y); int[] newRedData; int[] newGreenData; int[] newBlueData; if (bitofs < totalBits) { double[] redDCT = DCT(ref redData); double[] greenDCT = DCT(ref greenData); double[] blueDCT = DCT(ref blueData); int[] redDCTI = Quantize(ref redDCT, ref Q2); int[] greenDCTI = Quantize(ref greenDCT, ref Q2); int[] blueDCTI = Quantize(ref blueDCT, ref Q2); int[] blueDCTC = Quantize(ref blueDCT, ref Q); HideBits(ref blueDCTI, ref blueDCTC, ref bitofs, ref totalBits, ref codeBytes); double[] redDCT2 = DeQuantize(ref redDCTI, ref Q2); double[] greenDCT2 = DeQuantize(ref greenDCTI, ref Q2); double[] blueDCT2 = DeQuantize(ref blueDCTI, ref Q2); newRedData = IDCT(ref redDCT2); newGreenData = IDCT(ref greenDCT2); newBlueData = IDCT(ref blueDCT2); } else { newRedData = redData; newGreenData = greenData; newBlueData = blueData; } MapToRGBRange(ref newRedData); MapToRGBRange(ref newGreenData); MapToRGBRange(ref newBlueData); for(int dy=0;dy<8;dy++) { for(int dx=0;dx<8;dx++) { int col = (0xff<<24) + (newRedData[dx+(dy*8)]<<16) + (newGreenData[dx+(dy*8)]<<8) + (newBlueData[dx+(dy*8)]); response.SetPixel(x+dx,y+dy,Color.FromArgb(col)); } } } } if (bitofs < totalBits) throw new Exception("Failed to encode data - insufficient cover image coefficients"); return (response); } public static void HideBits(ref int[] DCTMatrix, ref int[] CMatrix, ref int bitofs, ref int totalBits, ref byte[] codeBytes) { int tempValue = 0; for (int u = 0; u < 8; u++) { for (int v = 0; v < 8; v++) { if ( (u != 0 || v != 0) && CMatrix[v+(u*8)] != 0 && DCTMatrix[v+(u*8)] != 0) { if (bitofs < totalBits) { tempValue = DCTMatrix[v + (u * 8)]; int bytePos = (bitofs) >> 3; int bitPos = (bitofs) % 8; byte mask = (byte)(1 << bitPos); byte value = (byte)((codeBytes[bytePos] & mask) >> bitPos); // 0 or 1. if (value == 0) { int a = DCTMatrix[v + (u * 8)] & (1 << HIDE_BIT_POS); if (a != 0) DCTMatrix[v + (u * 8)] |= (1 << HIDE_BIT_POS) - 1; DCTMatrix[v + (u * 8)] &= ~(1 << HIDE_BIT_POS); } else if (value == 1) { int a = DCTMatrix[v + (u * 8)] & (1 << HIDE_BIT_POS); if (a == 0) DCTMatrix[v + (u * 8)] &= ~((1 << HIDE_BIT_POS) - 1); DCTMatrix[v + (u * 8)] |= (1 << HIDE_BIT_POS); } if (DCTMatrix[v + (u * 8)] != 0) bitofs++; else DCTMatrix[v + (u * 8)] = tempValue; } } } } } public static void MapToRGBRange(ref int[] data) { for(int i=0;i<data.Length;i++) { data[i] += 128; if(data[i] < 0) data[i] = 0; else if(data[i] > 255) data[i] = 255; } } public static int[] GetRedChannelData(Bitmap b, int sx, int sy) { int[] data = new int[8 * 8]; for (int y = sy; y < (sy + 8); y++) { for (int x = sx; x < (sx + 8); x++) { uint col = (uint)b.GetPixel(x,y).ToArgb(); data[(x - sx) + ((y - sy) * 8)] = (int)((col >> 16) & 0xff) - 128; } } return (data); } public static int[] GetGreenChannelData(Bitmap b, int sx, int sy) { int[] data = new int[8 * 8]; for (int y = sy; y < (sy + 8); y++) { for (int x = sx; x < (sx + 8); x++) { uint col = (uint)b.GetPixel(x, y).ToArgb(); data[(x - sx) + ((y - sy) * 8)] = (int)((col >> 8) & 0xff) - 128; } } return (data); } public static int[] GetBlueChannelData(Bitmap b, int sx, int sy) { int[] data = new int[8 * 8]; for (int y = sy; y < (sy + 8); y++) { for (int x = sx; x < (sx + 8); x++) { uint col = (uint)b.GetPixel(x, y).ToArgb(); data[(x - sx) + ((y - sy) * 8)] = (int)((col >> 0) & 0xff) - 128; } } return (data); } public static int[] Quantize(ref double[] DCTMatrix, ref double[] Q) { int[] DCTMatrixOut = new int[8*8]; for (int u = 0; u < 8; u++) { for (int v = 0; v < 8; v++) { DCTMatrixOut[v + (u * 8)] = (int)Math.Round(DCTMatrix[v + (u * 8)] / Q[v + (u * 8)]); } } return(DCTMatrixOut); } public static double[] DeQuantize(ref int[] DCTMatrix, ref double[] Q) { double[] DCTMatrixOut = new double[8*8]; for (int u = 0; u < 8; u++) { for (int v = 0; v < 8; v++) { DCTMatrixOut[v + (u * 8)] = (double)DCTMatrix[v + (u * 8)] * Q[v + (u * 8)]; } } return(DCTMatrixOut); } public static double[] DCT(ref int[] data) { double[] DCTMatrix = new double[8 * 8]; for (int v = 0; v < 8; v++) { for (int u = 0; u < 8; u++) { double cu = 1; if (u == 0) cu = (1.0 / Math.Sqrt(2.0)); double cv = 1; if (v == 0) cv = (1.0 / Math.Sqrt(2.0)); double sum = 0.0; for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { double s = data[x + (y * 8)]; double dctVal = Math.Cos((2 * y + 1) * v * Math.PI / 16) * Math.Cos((2 * x + 1) * u * Math.PI / 16); sum += s * dctVal; } } DCTMatrix[u + (v * 8)] = (0.25 * cu * cv * sum); } } return (DCTMatrix); } public static int[] IDCT(ref double[] DCTMatrix) { int[] Matrix = new int[8 * 8]; for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { double sum = 0; for (int v = 0; v < 8; v++) { for (int u = 0; u < 8; u++) { double cu = 1; if (u == 0) cu = (1.0 / Math.Sqrt(2.0)); double cv = 1; if (v == 0) cv = (1.0 / Math.Sqrt(2.0)); double idctVal = (cu * cv) / 4.0 * Math.Cos((2 * y + 1) * v * Math.PI / 16) * Math.Cos((2 * x + 1) * u * Math.PI / 16); sum += (DCTMatrix[u + (v * 8)] * idctVal); } } Matrix[x + (y * 8)] = (int)Math.Round(sum); } } return (Matrix); } } public class Decoder { public static string Decode(Bitmap b, int expectedLength) { expectedLength *= Encoder.HIDE_COUNT; uint imgWidth = ((uint)b.Width) & ~((uint)7); // Maximum usable X resolution (divisible by 8). uint imgHeight = ((uint)b.Height) & ~((uint)7); // Maximum usable Y resolution (divisible by 8). // Setup the counters and byte data for the message to decode. byte[] codeBytes = new byte[expectedLength]; byte[] outBytes = new byte[expectedLength / Encoder.HIDE_COUNT]; int bitofs = 0; // Current bit position we've decoded too. int totalBits = (codeBytes.Length * 8); // Total number of bits to decode. for (int y = 0; y < imgHeight; y += 8) { for (int x = 0; x < imgWidth; x += 8) { int[] blueData = ImageKey.Encoder.GetBlueChannelData(b, x, y); double[] blueDCT = ImageKey.Encoder.DCT(ref blueData); int[] blueDCTI = ImageKey.Encoder.Quantize(ref blueDCT, ref Encoder.Q2); int[] blueDCTC = ImageKey.Encoder.Quantize(ref blueDCT, ref Encoder.Q); if (bitofs < totalBits) GetBits(ref blueDCTI, ref blueDCTC, ref bitofs, ref totalBits, ref codeBytes); } } bitofs = 0; for (int i = 0; i < (expectedLength / Encoder.HIDE_COUNT) * 8; i++) { int bytePos = (bitofs) >> 3; int bitPos = (bitofs) % 8; byte mask = (byte)(1 << bitPos); List<int> values = new List<int>(); int zeroCount = 0; int oneCount = 0; for (int j = 0; j < Encoder.HIDE_COUNT; j++) { int val = (codeBytes[bytePos + ((expectedLength / Encoder.HIDE_COUNT) * j)] & mask) >> bitPos; values.Add(val); if (val == 0) zeroCount++; else oneCount++; } if (oneCount >= zeroCount) outBytes[bytePos] |= mask; bitofs++; values.Clear(); } return (System.Text.Encoding.ASCII.GetString(outBytes)); } public static void GetBits(ref int[] DCTMatrix, ref int[] CMatrix, ref int bitofs, ref int totalBits, ref byte[] codeBytes) { for (int u = 0; u < 8; u++) { for (int v = 0; v < 8; v++) { if ((u != 0 || v != 0) && CMatrix[v + (u * 8)] != 0 && DCTMatrix[v + (u * 8)] != 0) { if (bitofs < totalBits) { int bytePos = (bitofs) >> 3; int bitPos = (bitofs) % 8; byte mask = (byte)(1 << bitPos); int value = DCTMatrix[v + (u * 8)] & (1 << Encoder.HIDE_BIT_POS); if (value != 0) codeBytes[bytePos] |= mask; bitofs++; } } } } } } } UPDATE: By switching to using a QR Code as the source message and swapping a pair of coefficients in each block instead of bit manipulation I've been able to get the message to survive the transform. However to get the message to come through without corruption I have to adjust both coefficients as well as swap them. For example swapping (3,4) and (4,3) in the DCT matrix and then respectively adding 8 and subtracting 8 as an arbitrary constant seems to work. This survives a re-JPEG'ing of 96 but any form of scaling/cropping destroys the message again. I was hoping that by operating on mid to low frequency values that the message would be preserved even under some light image manipulation.

    Read the article

  • Visual c++ opencv 2.1 contains()

    - by kaushalyjain
    how to check whether a given point is contained in a rectangle using the contains() function in Rect_ construct... Please give me the exact function and its parameters.Like when i type this Point b(2,2); Rect a(10,10,50,50); cout<< Rect_::contains(b); There is a compile error saying 1c:\users\kaushal\documents\visual studio 2008\projects\test1\test1.cpp(23) : error C2352: 'cv::Rect_<Tp::contains' : illegal call of non-static member function 1c:\opencv2.1\include\opencv\cxcore.hpp(385) : see declaration of 'cv::Rect<_Tp::contains'

    Read the article

  • Windows debugging - WinDbg

    - by Santhosh77
    Hi, I got the following error while debuggging a process with its core dump. 0:000 !lmi test.exe Loaded Module Info: [test.exe] Module: test Base Address: 00400000 Image Name: test.exe Machine Type: 332 (I386) Time Stamp: 4a3a38ec Thu Jun 18 07:54:04 2009 Size: 27000 CheckSum: 54c30 Characteristics: 10f Debug Data Dirs: Type Size VA Pointer MISC 110, 0, 21000 [Debug data not mapped] FPO 50, 0, 21110 [Debug data not mapped] CODEVIEW 31820, 0, 21160 [Debug data not mapped] - Can't validate symbols, if present. Image Type: FILE - Image read successfully from debugger. test.exe Symbol Type: CV - Symbols loaded successfully from image path. Load Report: cv symbols & lines Does any body know what the error "CODEVIEW 31820, 0, 21160 [Debug data not mapped] - Can't validate symbols, if present." really mean? Is this error meant that i can't read public/private symbols from the executable? If it is not so, why does the WinDbg debugger throws this typr of error? Thanks in advance, Santhosh.

    Read the article

  • Netlogo behaviorspace, How to export each experiment's plot in a separate directory with a unique name? (Answer is by using pathdir extension)

    - by Marzy
    I have a save-plots function which I call it in my final command of behavior space to export selected plots, I could create unique names for plots so they don't replace each other, for example my output file name for one of the plots is like this: DeathRates, PS true, HCHA false 100,true.csv Let FileNameDeathRates ( word "D: /Results/" "DeathRates, " "PS "PS? ", HCHA " HCHA? MPS "," CV? ".csv" ) So far is good, but I want is to have a directory with name of the experiment and export all plots of that experiment in that directory for example: Let DirName( word "D:/Results/" "PS "PS? ", HCHA " HCHA? MPS "," CV? ) Netlogo already exports plots with proper name and I just want the directory name to be different , and of course prior to the experiment the directory does not exist so the directory should be created first , I could not find a command to create a directory in netlogo without pathdir extension. Any idea on how can I do this? Thanks in advance ;)

    Read the article

  • What causes Python "Interpreter not Initialized" error?

    - by ?????
    I'm now on my third full day this week of trying to get OpenCV to work with Python. (I have been trying on and off for the past 6 months). I get this error Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. dlopen("/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/readline.so", 2); import readline # dynamically loaded from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/readline.so >>> import cv dlopen("./cv.so", 2); Fatal Python error: Interpreter not initialized (version mismatch?) and then it crashes (core dumps). python -v gives nothing after the dlopen. Any ideas from anyone who actually knows about this error?

    Read the article

  • How to give position zero of spinner a prompt value?

    - by Eugene H
    The database is then transferring the data to a spinner which I want to leave position 0 blank so I can add a item to the spinner with no value making it look like a prompt. I have been going at it all day. FAil after Fail MainActivity public class MainActivity extends Activity { Button AddBtn; EditText et; EditText cal; Spinner spn; SQLController SQLcon; ProgressDialog PD; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); AddBtn = (Button) findViewById(R.id.addbtn_id); et = (EditText) findViewById(R.id.et_id); cal = (EditText) findViewById(R.id.et_cal); spn = (Spinner) findViewById(R.id.spinner_id); spn.setOnItemSelectedListener(new OnItemSelectedListenerWrapper( new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { SQLcon.open(); Cursor c = SQLcon.readData(); if (c.moveToPosition(pos)) { String name = c.getString(c .getColumnIndex(DBhelper.MEMBER_NAME)); String calories = c.getString(c .getColumnIndex(DBhelper.KEY_CALORIES)); et.setText(name); cal.setText(calories); } SQLcon.close(); // closing database } @Override public void onNothingSelected(AdapterView<?> parent) { // TODO Auto-generated method stub } })); SQLcon = new SQLController(this); // opening database SQLcon.open(); loadtospinner(); AddBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new MyAsync().execute(); } }); } public void loadtospinner() { ArrayList<String> al = new ArrayList<String>(); Cursor c = SQLcon.readData(); c.moveToFirst(); while (!c.isAfterLast()) { String name = c.getString(c.getColumnIndex(DBhelper.MEMBER_NAME)); String calories = c.getString(c .getColumnIndex(DBhelper.KEY_CALORIES)); al.add(name + ", Calories: " + calories); c.moveToNext(); } ArrayAdapter<String> aa1 = new ArrayAdapter<String>( getApplicationContext(), android.R.layout.simple_spinner_item, al); spn.setAdapter(aa1); // closing database SQLcon.close(); } private class MyAsync extends AsyncTask<Void, Void, Void> { @Override protected void onPreExecute() { super.onPreExecute(); PD = new ProgressDialog(MainActivity.this); PD.setTitle("Please Wait.."); PD.setMessage("Loading..."); PD.setCancelable(false); PD.show(); } @Override protected Void doInBackground(Void... params) { String name = et.getText().toString(); String calories = cal.getText().toString(); // opening database SQLcon.open(); // insert data into table SQLcon.insertData(name, calories); return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); loadtospinner(); PD.dismiss(); } } } DataBase public class SQLController { private DBhelper dbhelper; private Context ourcontext; private SQLiteDatabase database; public SQLController(Context c) { ourcontext = c; } public SQLController open() throws SQLException { dbhelper = new DBhelper(ourcontext); database = dbhelper.getWritableDatabase(); return this; } public void close() { dbhelper.close(); } public void insertData(String name, String calories) { ContentValues cv = new ContentValues(); cv.put(DBhelper.MEMBER_NAME, name); cv.put(DBhelper.KEY_CALORIES, calories); database.insert(DBhelper.TABLE_MEMBER, null, cv); } public Cursor readData() { String[] allColumns = new String[] { DBhelper.MEMBER_ID, DBhelper.MEMBER_NAME, DBhelper.KEY_CALORIES }; Cursor c = database.query(DBhelper.TABLE_MEMBER, allColumns, null, null, null, null, null); if (c != null) { c.moveToFirst(); } return c; } } Helper public class DBhelper extends SQLiteOpenHelper { // TABLE INFORMATTION public static final String TABLE_MEMBER = "member"; public static final String MEMBER_ID = "_id"; public static final String MEMBER_NAME = "name"; public static final String KEY_CALORIES = "calories"; // DATABASE INFORMATION static final String DB_NAME = "MEMBER.DB"; static final int DB_VERSION = 2; // TABLE CREATION STATEMENT private static final String CREATE_TABLE = "create table " + TABLE_MEMBER + "(" + MEMBER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + MEMBER_NAME + " TEXT NOT NULL," + KEY_CALORIES + " INT NOT NULL);"; public DBhelper(Context context) { super(context, DB_NAME, null, DB_VERSION); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(CREATE_TABLE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub db.execSQL("DROP TABLE IF EXISTS " + TABLE_MEMBER); onCreate(db); } }

    Read the article

  • Correct term for PSD to HTML to CMS

    - by John Magnolia
    Hi, I have heard a lot of different terms to describe the process of turning a website design into a editable CMS. Currently I take the design and "slice" this up into HTML and CSS then I "plug" this into a CMS. I would class this as frontend development depending on the level of customisation required for the CMS. The reason I ask is I am currently writing up my CV and have become stuck on the correct term for this. Kind Regards

    Read the article

  • Interviews: Going Beyond the Technical Quiz

    - by Tony Davis
    All developers will be familiar with the basic format of a technical interview. After a bout of CV-trawling to gauge basic experience, strengths and weaknesses, the interview turns technical. The whiteboard takes center stage and the challenge is set to design a function or query, or solve what on the face of it might seem a disarmingly simple programming puzzle. Most developers will have experienced those few panic-stricken moments, when one’s mind goes as blank as the whiteboard, before un-popping the marker pen, and hopefully one’s mental functions, to work through the problem. It is a way to probe the candidate’s knowledge of basic programming structures and techniques and to challenge their critical thinking. However, these challenges or puzzles, often devised by some of the smartest brains in the development team, have a tendency to become unnecessarily ‘tricksy’. They often seem somewhat academic in nature. While the candidate straight out of IT school might breeze through the construction of a Markov chain, a candidate with bags of practical experience but less in the way of formal training could become nonplussed. Also, a whiteboard and a marker pen make up only a very small part of the toolkit that a programmer will use in everyday work. I remember vividly my first job interview, for a position as technical editor. It went well, but after the usual CV grilling and technical questions, I was only halfway there. Later, they sat me alongside a team of editors, in front of a computer loaded with MS Word and copy of SQL Server Query Analyzer, and my task was to edit a real chapter for a real SQL Server book that they planned to publish, including validating and testing all the code. It was a tough challenge but I came away with a sound knowledge of the sort of work I’d do, and its context. It makes perfect sense, yet my impression is that many organizations don’t do this. Indeed, it is only relatively recently that Red Gate started to move over to this model for developer interviews. Now, instead of, or perhaps in addition to, the whiteboard challenges, the candidate can expect to sit with their prospective team, in front of Visual Studio, loaded with all the useful tools in the developer’s kit (ReSharper and so on) and asked to, for example, analyze and improve a real piece of software. The same principles should apply when interviewing for a database positon. In addition to the usual questions challenging the candidate’s knowledge of such things as b-trees, object permissions, database recovery models, and so on, sit the candidate down with the other database developers or DBAs. Arm them with a copy of Management Studio, and a few other tools, then challenge them to discover the flaws in a stored procedure, and improve its performance. Or present them with a corrupt database and ask them to get the database back online, and discover the cause of the corruption.

    Read the article

  • What common term could be used for Web Services, Windows Services etc

    - by Shamim Hafiz
    My question is primarily concerned with making a CV. Normally under the Language section we list the individual programming Languages we've used. For example, C#, C++, PHP. Under the Platform section we can list the various operating systems and devices. Under which category would Web Services/Windows Services fall? My point is these are not platforms by themselves and surely they aren't a language. Is there any common term that can be used to describe these?

    Read the article

  • What's up with LDoms: Part 5 - A few Words about Consoles

    - by Stefan Hinker
    Back again to look at a detail of LDom configuration that is often forgotten - the virtual console server. Remember, LDoms are SPARC systems.  As such, each guest will have it's own OBP running.  And to connect to that OBP, the administrator will need a console connection.  Since it's OBP, and not some x86 BIOS, this console will be very serial in nature ;-)  It's really very much like in the good old days, where we had a terminal concentrator where all those serial cables ended up in.  Just like with other components in LDoms, the virtualized solution looks very similar. Every LDom guest requires exactly one console connection.  Envision this similar to the RS-232 port on older SPARC systems.  The LDom framework provides one or more console services that provide access to these connections.  This would be the virtual equivalent of a network terminal server (NTS), where all those serial cables are plugged in.  In the physical world, we'd have a list somewhere, that would tell us which TCP-Port of the NTS was connected to which server.  "ldm list" does just that: root@sun # ldm list NAME STATE FLAGS CONS VCPU MEMORY UTIL UPTIME primary active -n-cv- UART 16 7680M 0.4% 27d 8h 22m jupiter bound ------ 5002 20 8G mars active -n---- 5000 2 8G 0.5% 55d 14h 10m venus active -n---- 5001 2 8G 0.5% 56d 40m pluto inactive ------ 4 4G The column marked "CONS" tells us, where to reach the console of each domain. In the case of the primary domain, this is actually a (more) physical connection - it's the console connection of the physical system, which is either reachable via the ILOM of that system, or directly via the serial console port on the chassis. All the other guests are reachable through the console service which we created during the inital setup of the system.  Note that pluto does not have a port assigned.  This is because pluto is not yet bound.  (Binding can be viewed very much as the assembly of computer parts - CPU, Memory, disks, network adapters and a serial console cable are all put together when binding the domain.)  Unless we set the port number explicitly, LDoms Manager will do this on a first come, first serve basis.  For just a few domains, this is fine.  For larger deployments, it might be a good idea to assign these port numbers manually using the "ldm set-vcons" command.  However, there is even better magic associated with virtual consoles. You can group several domains into one console group, reachable through one TCP port of the console service.  This can be useful when several groups of administrators are to be given access to different domains, or for other grouping reasons.  Here's an example: root@sun # ldm set-vcons group=planets service=console jupiter root@sun # ldm set-vcons group=planets service=console pluto root@sun # ldm bind jupiter root@sun # ldm bind pluto root@sun # ldm list NAME STATE FLAGS CONS VCPU MEMORY UTIL UPTIME primary active -n-cv- UART 16 7680M 6.1% 27d 8h 24m jupiter bound ------ 5002 200 8G mars active -n---- 5000 2 8G 0.6% 55d 14h 12m pluto bound ------ 5002 4 4G venus active -n---- 5001 2 8G 0.5% 56d 42m root@sun # telnet localhost 5002 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. sun-vnts-planets: h, l, c{id}, n{name}, q:l DOMAIN ID DOMAIN NAME DOMAIN STATE 2 jupiter online 3 pluto online sun-vnts-planets: h, l, c{id}, n{name}, q:npluto Connecting to console "pluto" in group "planets" .... Press ~? for control options .. What I did here was add the two domains pluto and jupiter to a new console group called "planets" on the service "console" running in the primary domain.  Simply using a group name will create such a group, if it doesn't already exist.  By default, each domain has its own group, using the domain name as the group name.  The group will be available on port 5002, chosen by LDoms Manager because I didn't specify it.  If I connect to that console group, I will now first be prompted to choose the domain I want to connect to from a little menu. Finally, here's an example how to assign port numbers explicitly: root@sun # ldm set-vcons port=5044 group=pluto service=console pluto root@sun # ldm bind pluto root@sun # ldm list NAME STATE FLAGS CONS VCPU MEMORY UTIL UPTIME primary active -n-cv- UART 16 7680M 3.8% 27d 8h 54m jupiter active -t---- 5002 200 8G 0.5% 30m mars active -n---- 5000 2 8G 0.6% 55d 14h 43m pluto bound ------ 5044 4 4G venus active -n---- 5001 2 8G 0.4% 56d 1h 13m With this, pluto would always be reachable on port 5044 in its own exclusive console group, no matter in which order other domains are bound. Now, you might be wondering why we always have to mention the console service name, "console" in all the examples here.  The simple answer is because there could be more than one such console service.  For all "normal" use, a single console service is absolutely sufficient.  But the system is flexible enough to allow more than that single one, should you need them.  In fact, you could even configure such a console service on a domain other than the primary (or control domain), which would make that domain a real console server.  I actually have a customer who does just that - they want to separate console access from the control domain functionality.  But this is definately a rather sophisticated setup. Something I don't want to go into in this post is access control.  vntsd, which is the daemon providing all these console services, is fully RBAC-aware, and you can configure authorizations for individual users to connect to console groups or individual domain's consoles.  If you can't wait until I get around to security, check out the man page of vntsd. Further reading: The Admin Guide is rather reserved on this subject.  I do recommend to check out the Reference Manual. The manpage for vntsd will discuss all the control sequences as well as the grouping and authorizations mentioned here.

    Read the article

  • Journée du recrutement en Ingénierie Informatique, salon Les jeudis.com le 24 février à Nantes : plus de 500 postes proposés

    Journée du recrutement en Ingénierie Informatique Salon Les jeudis.com le 24 février à Nantes : plus de 500 postes proposés Après le succès qu'a connu l'édition parisienne de son salon, Lesjeudis.com invite les informaticiens de la région Nantaise à se rendre à la prochaine Journée du recrutement en Ingénierie informatique. Plus de 500 postes y seront à pourvoir. Cette journée se tiendra le 24 février 2011 à la Cité Internationale des Congrès de Nantes, de 10h à 18h. [IMG]http://www.lesjeudis.com/img/salon/salon_lesjeudis.gif[/IMG] N'oubliez surtout pas vos CV.

    Read the article

  • Using boost locks for RAII access to a semaphore

    - by dan
    Suppose I write a C++ semaphore class with an interface that models the boost Lockable concept (i.e. lock(); unlock(); try_lock(); etc.). Is it safe/recommended to use boost locks for RAII access to such an object? In other words, do boost locks (and/or other related parts of the boost thread library) assume that the Lockable concept will only be modeled by mutex-like objects which are locked and unlocked from the same thread? My guess is that it should be OK to use a semaphore as a model for Lockable. I've browsed through some of the boost source and it "seems" OK. The locks don't appear to store explicit references to this_thread or anything like that. Moreover, the Lockable concept doesn't have any function like whichThreadOwnsMe(). It also looks like I should even be able to pass a boost::unique_lock<MySemaphore> reference to boost::condition_variable_any::wait. However, the documentation is not explicitly clear about the requirements. To illustrate what I mean, consider a bare-bones binary semaphore class along these lines: class MySemaphore{ bool locked; boost::mutex mx; boost::condition_variable cv; public: void lock(){ boost::unique_lock<boost::mutex> lck(mx); while(locked) cv.wait(lck); locked=true; } void unlock(){ { boost::lock_guard<boost::mutex> lck(mx); if(!locked) error(); locked=false; } cv.notify_one(); } // bool try_lock(); void error(); etc. } Now suppose that somewhere, either on an object or globally, I have MySemaphore sem; I want to lock and unlock it using RAII. Also I want to be able to "pass" ownership of the lock from one thread to another. For example, in one thread I execute void doTask() { boost::unique_lock<MySemaphore> lock(sem); doSomeWorkWithSharedObject(); signalToSecondThread(); waitForSignalAck(); lock.release(); } While another thread is executing something like { waitForSignalFromFirstThread(); ackSignal(); boost::unique_lock<MySemaphore>(sem,boost::adopt_lock_t()); doMoreWorkWithSameSharedObject(); } The reason I am doing this is that I don't want anyone else to be able to get the lock on sem in between the time that the first thread executes doSomeWorkWithSharedObject() and the time the second executes doMoreWorkWithSameSharedObject(). Basically, I'm splitting one task into two parts. And the reason I'm splitting the task up is because (1) I want the first part of the task to get started as soon as possible, (2) I want to guarantee that the first part is complete before doTask() returns, and (3) I want the second, more time-consuming part of the task to be completed by another thread, possibly chosen from a pool of slave threads that are waiting around to finish tasks that have been started by master threads. NOTE: I recently posted this same question (sort of) here http://stackoverflow.com/questions/2754884/unlocking-a-mutex-from-a-different-thread-c but I confused mutexes with semaphores, and so the question about using boost locks didn't really get addressed.

    Read the article

  • I don't understand how work call_once

    - by SABROG
    Please help me understand how work call_once Here is thread-safe code. I don't understand why this need Thread Local Storage and global_epoch variables. Variable _fast_pthread_once_per_thread_epoch can be changed to constant/enum like {FAST_PTHREAD_ONCE_INIT, BEING_INITIALIZED, FINISH_INITIALIZED}. Why needed count calls in global_epoch? I think this code can be rewriting with logc: if flag FINISH_INITIALIZED do nothing, else go to block with mutexes and this all. #ifndef FAST_PTHREAD_ONCE_H #define FAST_PTHREAD_ONCE_H #include #include typedef sig_atomic_t fast_pthread_once_t; #define FAST_PTHREAD_ONCE_INIT SIG_ATOMIC_MAX extern __thread fast_pthread_once_t _fast_pthread_once_per_thread_epoch; #ifdef __cplusplus extern "C" { #endif extern void fast_pthread_once( pthread_once_t *once, void (*func)(void) ); inline static void fast_pthread_once_inline( fast_pthread_once_t *once, void (*func)(void) ) { fast_pthread_once_t x = *once; /* unprotected access */ if ( x _fast_pthread_once_per_thread_epoch ) { fast_pthread_once( once, func ); } } #ifdef __cplusplus } #endif #endif FAST_PTHREAD_ONCE_H Source fast_pthread_once.c The source is written in C. The lines of the primary function are numbered for reference in the subsequent correctness argument. #include "fast_pthread_once.h" #include static pthread_mutex_t mu = PTHREAD_MUTEX_INITIALIZER; /* protects global_epoch and all fast_pthread_once_t writes */ static pthread_cond_t cv = PTHREAD_COND_INITIALIZER; /* signalled whenever a fast_pthread_once_t is finalized */ #define BEING_INITIALIZED (FAST_PTHREAD_ONCE_INIT - 1) static fast_pthread_once_t global_epoch = 0; /* under mu */ __thread fast_pthread_once_t _fast_pthread_once_per_thread_epoch; static void check( int x ) { if ( x == 0 ) abort(); } void fast_pthread_once( fast_pthread_once_t *once, void (*func)(void) ) { /*01*/ fast_pthread_once_t x = *once; /* unprotected access */ /*02*/ if ( x _fast_pthread_once_per_thread_epoch ) { /*03*/ check( pthread_mutex_lock(µ) == 0 ); /*04*/ if ( *once == FAST_PTHREAD_ONCE_INIT ) { /*05*/ *once = BEING_INITIALIZED; /*06*/ check( pthread_mutex_unlock(µ) == 0 ); /*07*/ (*func)(); /*08*/ check( pthread_mutex_lock(µ) == 0 ); /*09*/ global_epoch++; /*10*/ *once = global_epoch; /*11*/ check( pthread_cond_broadcast(&cv;) == 0 ); /*12*/ } else { /*13*/ while ( *once == BEING_INITIALIZED ) { /*14*/ check( pthread_cond_wait(&cv;, µ) == 0 ); /*15*/ } /*16*/ } /*17*/ _fast_pthread_once_per_thread_epoch = global_epoch; /*18*/ check (pthread_mutex_unlock(µ) == 0); } } This code from BOOST: #ifndef BOOST_THREAD_PTHREAD_ONCE_HPP #define BOOST_THREAD_PTHREAD_ONCE_HPP // once.hpp // // (C) Copyright 2007-8 Anthony Williams // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include "pthread_mutex_scoped_lock.hpp" #include #include #include namespace boost { struct once_flag { boost::uintmax_t epoch; }; namespace detail { BOOST_THREAD_DECL boost::uintmax_t& get_once_per_thread_epoch(); BOOST_THREAD_DECL extern boost::uintmax_t once_global_epoch; BOOST_THREAD_DECL extern pthread_mutex_t once_epoch_mutex; BOOST_THREAD_DECL extern pthread_cond_t once_epoch_cv; } #define BOOST_ONCE_INITIAL_FLAG_VALUE 0 #define BOOST_ONCE_INIT {BOOST_ONCE_INITIAL_FLAG_VALUE} // Based on Mike Burrows fast_pthread_once algorithm as described in // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2444.html template void call_once(once_flag& flag,Function f) { static boost::uintmax_t const uninitialized_flag=BOOST_ONCE_INITIAL_FLAG_VALUE; static boost::uintmax_t const being_initialized=uninitialized_flag+1; boost::uintmax_t const epoch=flag.epoch; boost::uintmax_t& this_thread_epoch=detail::get_once_per_thread_epoch(); if(epoch #endif I right understand, boost don't use atomic operation, so code from boost not thread-safe?

    Read the article

  • Camera Preview App in Android throwing many errors (Nexus 4)

    - by Jagatheesan Jack
    I am trying to develop a camera app that takes a picture and saves it in a SQLite database. I get a lot of errors when executing the application. My code is as below. Any idea? CameraActivity.java private Camera mCamera; private CameraPreview mPreview; private int CAMERA_RETURN_CODE=100; private static final String TAG = "Take_Picture"; public static final int MEDIA_TYPE_IMAGE = 1; public static final int MEDIA_TYPE_VIDEO = 2; private Bitmap cameraBmp; private int MAX_FACES = 1; private Face[] faceList; public RectF[] rects; private Canvas canvas; private Drawable pictureDataDrawable; private MySQLiteHelper database; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.camera_activity); //this.requestWindowFeature(Window.FEATURE_NO_TITLE); //Create an instance of Camera mCamera = getCameraInstance(); setCameraDisplayOrientation(this, 0, mCamera); // Create our Preview view and set it as the content of our activity. mPreview = new CameraPreview(this, mCamera); FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview); preview.addView(mPreview); database = new MySQLiteHelper(getApplicationContext()); Button captureButton = (Button) findViewById(R.id.button_capture); captureButton.setOnClickListener( new View.OnClickListener() { private PictureCallback mPicture; @Override public void onClick(View v) { //mCamera.startPreview(); // get an image from the camera mCamera.takePicture(null, null, mPicture); PictureCallback mPicture = new PictureCallback() { @Override public void onPictureTaken(byte[] data, Camera camera) { try{ if (data != null) database.addEntry(data); //mCamera.startPreview(); } catch(Exception e){ Log.d(TAG, e.getMessage()); } } } ); } /** A safe way to get an instance of the Camera object. */ public static Camera getCameraInstance(){ Camera c = null; try { c = Camera.open(c.getNumberOfCameras()-1); // attempt to get a Camera instance } catch (Exception e){ // Camera is not available (in use or does not exist) } return c; // returns null if camera is unavailable } public static void setCameraDisplayOrientation(Activity activity, int cameraId, android.hardware.Camera camera) { android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); android.hardware.Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay() .getRotation(); int degrees = 360; /*switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; }*/ int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); } @Override protected void onPause() { super.onPause(); //releaseMediaRecorder(); // if you are using MediaRecorder, release it first releaseCamera(); // release the camera immediately on pause event } private void releaseCamera(){ if (mCamera != null){ mCamera.release(); // release the camera for other applications mCamera = null; } } public void startFaceDetection(){ // Try starting Face Detection Camera.Parameters params = mCamera.getParameters(); // start face detection only *after* preview has started if (params.getMaxNumDetectedFaces() > 0){ // camera supports face detection, so can start it: mCamera.startFaceDetection(); } } CameraPreview.java public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; private Camera mCamera; private String TAG; private List<Size> mSupportedPreviewSizes; public CameraPreview(Context context, Camera camera) { super(context); mCamera = camera; // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android versions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { mCamera.setPreviewDisplay(holder); mCamera.setDisplayOrientation(90); mCamera.startPreview(); } catch (IOException e) { Log.d(TAG, "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // empty. Take care of releasing the Camera preview in your activity. } public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { // If your preview can change or rotate, take care of those events here. // Make sure to stop the preview before resizing or reformatting it. if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try { mCamera.setPreviewDisplay(mHolder); mCamera.startPreview(); } catch (Exception e){ Log.d(TAG, "Error starting camera preview: " + e.getMessage()); } } public void setCamera(Camera camera) { if (mCamera == camera) { return; } mCamera = camera; if (mCamera != null) { List<Size> localSizes = mCamera.getParameters().getSupportedPreviewSizes(); mSupportedPreviewSizes = localSizes; requestLayout(); try { mCamera.setPreviewDisplay(mHolder); } catch (IOException e) { e.printStackTrace(); } /* Important: Call startPreview() to start updating the preview surface. Preview must be started before you can take a picture. */ mCamera.startPreview(); } } MySQLiteHelper.java private static final int count = 0; public static final String TABLE_IMAGE = "images"; public static final String COLUMN_ID = "_id"; public static final String PICTURE_DATA = "picture"; public static final String DATABASE_NAME = "images.db"; public static final int DATABASE_VERSION = 1; public static final String DATABASE_CREATE = "create table " + TABLE_IMAGE + "(" + COLUMN_ID + " integer primary key autoincrement, " + PICTURE_DATA + " blob not null);"; public static SQLiteDatabase database; private static String TAG = "test"; public MySQLiteHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); // TODO Auto-generated constructor stub } public MySQLiteHelper(Context context, String name, CursorFactory factory, int version, DatabaseErrorHandler errorHandler) { super(context, name, factory, version, errorHandler); // TODO Auto-generated constructor stub } @Override public void onCreate(SQLiteDatabase database) { database.execSQL(DATABASE_CREATE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w(MySQLiteHelper.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); db.execSQL("DROP TABLE IF EXISTS " + TABLE_IMAGE); onCreate(db); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub } public void addEntry(byte [] array) throws SQLiteException{ ContentValues cv = new ContentValues(); //cv.put(KEY_NAME, name); cv.put(PICTURE_DATA, array); database.insert( TABLE_IMAGE, null, cv ); Log.w(TAG , "added " +count+ "images"); database.close(); } Errors 11-07 23:28:39.050: E/mm-libcamera2(176): PROFILE HAL: stopPreview(): E: 1383838119.067589459 11-07 23:28:39.050: E/mm-camera(201): config_MSG_ID_STOP_ACK: streamon_mask is not clear. Should not call PP_Release_HW 11-07 23:28:39.090: E/QCameraHWI(176): android::status_t android::QCameraHardwareInterface::setPreviewWindow(preview_stream_ops_t*):Received Setting NULL preview window 11-07 23:28:39.090: E/QCameraHWI(176): android::status_t android::QCameraHardwareInterface::setPreviewWindow(preview_stream_ops_t*): mPreviewWindow = 0x0x0, mStreamDisplay = 0x0xb8a9df90 11-07 23:28:39.090: E/mm-camera(201): config_shutdown_pp Camera not in streaming mode. Returning. 11-07 23:28:39.090: E/mm-camera(201): vfe_ops_deinit: E 11-07 23:28:39.120: E/qcom_sensors_hal(533): hal_process_report_ind: Bad item quality: 11 11-07 23:28:39.310: E/qcom_sensors_hal(533): hal_process_report_ind: Bad item quality: 11 11-07 23:28:39.330: E/mm-camera(201): sensor_load_chromatix: libchromatix_imx119_preview.so: 30 11-07 23:28:39.340: E/mm-camera(201): vfe_ops_init: E 11-07 23:28:39.360: E/mm-camera(201): vfe_legacy_stats_buffer_init: AEC_STATS_BUFNUM 11-07 23:28:39.360: E/mm-camera(201): vfe_legacy_stats_buffer_init: AEC_STATS_BUFNUM 11-07 23:28:39.360: E/mm-camera(201): mctl_init_stats_proc_info: snap_max_line_cnt =25776 11-07 23:28:39.440: E/QCameraHWI(176): android::status_t android::QCameraHardwareInterface::setPreviewWindow(preview_stream_ops_t*): mPreviewWindow = 0x0xb8aa1780, mStreamDisplay = 0x0xb8a9df90 11-07 23:28:39.440: E/mm-camera(201): config_proc_CAMERA_SET_INFORM_STARTPREVIEW 11-07 23:28:39.450: E/mm-camera(201): config_update_stream_info Storing stream parameters for video inst 1 as : width = 640, height 480, format = 1 inst_handle = 810081 cid = 0 11-07 23:28:39.490: E/mm-camera(201): config_update_stream_info Storing stream parameters for video inst 3 as : width = 640, height 480, format = 1 inst_handle = 830083 cid = 0 11-07 23:28:39.490: E/mm-camera(201): config_update_stream_info Storing stream parameters for video inst 4 as : width = 512, height 384, format = 1 inst_handle = 840084 cid = 0 11-07 23:28:39.500: E/mm-camera(201): config_decide_vfe_outputs: Ports Used 3, Op mode 1 11-07 23:28:39.500: E/mm-camera(201): config_decide_vfe_outputs Current mode 0 Full size streaming : Disabled 11-07 23:28:39.500: E/mm-camera(201): config_decide_vfe_outputs: Primary: 640x480, extra_pad: 0x0, Fmt: 1, Type: 1, Path: 1 11-07 23:28:39.500: E/mm-camera(201): config_decide_vfe_outputs: Secondary: 640x480, extra_pad: 0x0, Fmt: 1, Type: 3, Path: 4 11-07 23:28:39.510: E/mm-camera(201): config_update_inst_handles Updated the inst handles as 810081, 830083, 0, 0 11-07 23:28:39.631: E/mm-camera(201): sensor_load_chromatix: libchromatix_imx119_preview.so: 30 11-07 23:28:39.631: E/mm-camera(201): camif_client_set_params: camif has associated with obj mask 0x1 11-07 23:28:39.631: E/mm-camera(201): config_v2_CAMERA_START_common CAMIF_PARAMS_ADD_OBJ_ID failed -1 11-07 23:28:39.641: E/mm-camera(201): vfe_operation_config: format 3 11-07 23:28:39.641: E/mm-camera(201): vfe_operation_config:vfe_op_mode=5 11-07 23:28:39.641: E/mm-camera(201): Invalid ASD Set Params Type 11-07 23:28:39.641: E/mm-camera(201): vfe_set_bestshot: Bestshot mode not changed

    Read the article

  • I can't compile android projetc wiht JNI code

    - by lobi
    I'm trying to build simple android app with some JNI code. When I press build project in eclipse I get this error: Description Resource Path Location Type fatal error: algorithm: No such file or directory Tracker line 56, external location: /home/slani/code/OpenCV-2.4.6-android-sdk/sdk/native/jni/include/opencv2/core/core.hpp C/C++ Problem make: *** [obj/local/armeabi/objs/detect_jni/detect_jni.o] Error 1 Tracker C/C++ Problem Line 56 in core.hpp contains the relevant include. This is my Android.mk file jni folder: LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) include /home/slani/code/OpenCV-2.4.6-android-sdk/sdk/native/jni/OpenCV.mk LOCAL_MODULE := detect_jni LOCAL_SRC_FILES := detect_jni.cpp include $(BUILD_SHARED_LIBRARY) This is my Aplication.mk file in jni folder: APP_STL := gnustl_static APP_CPPFLAGS := -frtti -fexceptions APP_ABI := armeabi-v7a APP_PLATFORM := all This is my .cpp file: #include <jni.h> #include <opencv/cv.h> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/features2d/features2d.hpp> using namespace cv; extern "C"{ JNIEXPORT void JNICALL Java_com_slani_tracker_OpenCamera_findObject((JNIEnv *env, jlong addRgba, jlong addHsv); JNIEXPORT void JNICALL Java_com_slani_tracker_OpenCamera_findObject((JNIEnv *env, jlong addRgba, jlong addHsv) { Mat& rgba = *(Mat*)addRgba; Mat& hsv = *(Mat*)addHsv; cvtColor(rgba, hsv,CV_RGBA2HSV); } } Can someone please help me? What could be causing this problem? Thanks

    Read the article

  • How do I process the configure file when cross-compiling with mingw?

    - by vy32
    I have a small open source program that builds with an autoconf configure script. I ran configure I tried to compile with: make CC="/opt/local/bin/i386-mingw32-g++" That didn't work because the configure script found include files that were not available to the mingw system. So then I tried: ./configure CC="/opt/local/bin/i386-mingw32-g++" But that didn't work; the configure script gives me this error: ./configure: line 5209: syntax error near unexpected token `newline' ./configure: line 5209: ` *_cv_*' Because of this code: # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. # So, we kill variables containing newlines. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. ( for ac_var in `(set) 2>&1 | sed -n 's/^\(a-zA-Z_a-zA-Z0-9_*\)=.*/\1/p'`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_* fi Which is generated then the AC_OUTPUT is called. Any thoughts? Is there a correct way to do this?

    Read the article

  • help('modules') crashing?

    - by Chris
    I was trying to install a module for opencv and added an opencv.pth file to the folder beyond my sites.py file. I have since deleted it and no change. When I try to run help('modules'), I get the following error: Please wait a moment while I gather a list of all available modules... /System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/twisted/words/im/init.py:8: UserWarning: twisted.im will be undergoing a rewrite at some point in the future. warnings.warn("twisted.im will be undergoing a rewrite at some point in the future.") /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pkgutil.py:110: DeprecationWarning: The wxPython compatibility package is no longer automatically generated or actively maintained. Please switch to the wx package as soon as possible. import(name) Traceback (most recent call last): File "", line 1, in File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site.py", line 348, in call return pydoc.help(*args, **kwds) File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pydoc.py", line 1644, in call self.help(request) File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pydoc.py", line 1681, in help elif request == 'modules': self.listmodules() File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pydoc.py", line 1802, in listmodules ModuleScanner().run(callback) File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pydoc.py", line 1853, in run for importer, modname, ispkg in pkgutil.walk_packages(): File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pkgutil.py", line 110, in walk_packages import(name) File "/BinaryCache/wxWidgets/wxWidgets-11~262/Root/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/wxaddons/init.py", line 180, in import_hook File "/Library/Python/2.5/site-packages/ctypes_opencv/init.py", line 19, in from ctypes_opencv.cv import * File "/BinaryCache/wxWidgets/wxWidgets-11~262/Root/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/wxaddons/init.py", line 180, in import_hook File "/Library/Python/2.5/site-packages/ctypes_opencv/cv.py", line 2567, in ('desc', CvMat_r, 1), # CvMat* desc File "/Library/Python/2.5/site-packages/ctypes_opencv/cxcore.py", line 114, in cfunc return CFUNCTYPE(result, *atypes)((name, dll), tuple(aflags)) AttributeError: dlsym(0x2674d10, cvCreateFeatureTree): symbol not found What gives?!

    Read the article

  • webkit - css transition effect on a div

    - by Mak Killbers
    I am trying to do fadein/out effect when I change innerHTML of a div. Even tried example given at safari doc I want the div to fade-out, change the contents and then fade-in again with new content. <style> .cv { background-color: #eee; -webkit-transition: all 1s ease-in-out;} .cf {opacity: 0;} </style> <body> <div id="main"> <div id="c"> OLD </div> </div> </body> <script> var c = document.getElementById("c"); c.setAttribute("class", "cf"); c.innerHTML = ''; c.appendChild(fragment); c.setAttribute("class", "cv"); </script> Please help me here

    Read the article

  • Why won't this work; opencv Mat_<float>

    - by user1371674
    I can't seem to get this to work. I'm trying to get the pixel value of an image but first need to change the color of the image, but since I cannot use int or just Mat because the values are not whole numbers, I have to use and because of that errors pop up when I try to run this on the cmd. int main(int argc, char **argv) { Mat img = imread(argv[1]); ofstream myfile; Mat_<float> MatBlue = img; int rows1 = MatBlue.rows; int cols1 = MatBlue.cols; for(int x = 0; x < cols1; x++) { for(int y = 0; y < rows1; y++) { float val = MatBlue.at<cv::Vec3b>(y, x)[1]; MatBlue.at<cv::Vec3b>(y, x)[0] = val + 1; } } }

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11  | Next Page >