bit

How to convert a 16 bit to an 8 bit image in OpenCV?

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a 16bit grayscale image and I want to convert it to a 8bit grayscale image in OpenCV for python to use it with various functions (like findContours etc.). Is it possible to do it in python or I have to switch to C++? 回答1: You can use numpy conversion methods as an OpenCV mat is a numpy array. This works: img8 = ( img16 / 256 ). astype ( 'uint8' ) 回答2: You can do this in Python using NumPy by mapping the image trough a lookup table. import numpy as np def map_uint16_to_uint8 ( img , lower_bound = None , upper_bound = None ):

How to tell if a 32 bit int can fit in a 16 bit short

匿名 (未验证) 提交于 2019-12-03 08:42:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Using only: ! ~ & ^ | + << >> I need to find out if a signed 32 bit integer can be represented as a 16 bit, two's complement integer. My first thoughts were to separate the MSB 16 bits and the LSB 16 bits and then use a mask to and the last 16 bits so if its not zero, it wont be able to be represented and then use that number to check the MSB bits. An example of the function I need to write is: fitsInShort(33000) = 0 (cant be represented) and fitsInShort(-32768) = 1 (can be represented) 回答1: bool fits16(int x) { short y = x; return y == x; }

Determining 32 vs 64 bit in C++

匿名 (未验证) 提交于 2019-12-03 08:42:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm looking for a way to reliably determine whether C++ code is being compiled in 32 vs 64 bit. We've come up with what we think is a reasonable solution using macros, but was curious to know if people could think of cases where this might fail or if there is a better way to do this. Please note we are trying to do this in a cross-platform, multiple compiler environment. #if ((ULONG_MAX) == (UINT_MAX)) # define IS32BIT #else # define IS64BIT #endif #ifdef IS64BIT DoMy64BitOperation() #else DoMy32BitOperation() #endif Thanks. 回答1:

Number of unset bit left of most significant set bit?

匿名 (未验证) 提交于 2019-12-03 08:42:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Assuming the 64bit integer 0x000000000000FFFF which would be represented as 00000000 00000000 00000000 00000000 00000000 00000000 >11111111 11111111 How do I find the amount of unset bits to the left of the most significant set bit (the one marked with >) ? 回答1: // clear all bits except the lowest set bit x &= -x; // if x==0, add 0, otherwise add x - 1. // This sets all bits below the one set above to 1. x+= (-(x==0))&(x - 1); return 64 - count_bits_set(x); Where count_bits_set is the fastest version of counting bits you can find. See https:

Are there any good reasons to use bit shifting except for quick math?

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I understand bitwise operations and how they might be useful for different purposes, e.g. permissions. However, I don't seem to understand what use the bit shift operators are. I understand how they work, but I can't think of any scenarios where I might want to use them unless I want to do some really quick multiplication or division. Are there any other reasons to use bit-shifting? 回答1: There are many reasons, here are some: Let's say you represent a black and white image as a sequence of bits and you want to set a single pixel in

Why is the maximum value of an unsigned n-bit integer 2^n-1 and not 2^n?

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: The maximum value of an n -bit integer is 2 n -1. Why do we have the "minus 1"? Why isn't the maximum just 2 n ? 回答1: The -1 is because integers start at 0, but our counting starts at 1. So, 2^32-1 is the maximum value for a 32-bit unsigned integer (32 binary digits). 2^32 is the number of possible values . To simplify why, look at decimal. 10^2-1 is the maximum value of a 2-digit decimal number (99). Because our intuitive human counting starts at 1, but integers are 0-based, 10^2 is the number of values (100). 回答2: 2^32 in binary: 1

Why is float not a double on a 64-bit system? [closed]

匿名 (未验证) 提交于 2019-12-03 08:39:56
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Considering an int will be 4 bytes on a 32-bit system and 8 bytes on a 64-bit system, why is float not treated the same? Why is size of a double != size of a float on a 64-bit system? Considering that the best native integer type is selected when I declare an int (which results in higher performance ), shouldn't the same happen for float (which also results in a performance increase)? Related question: Is it a bad idea to declare a type my_float (pardon the name!) that is float on 32-bit systems and double on 64-bit systems? 回答1:

How to debug division by zero exception in Internet Explorer?

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: i am hosting Internet Explorer in a Windows application. i can scroll down to the bottom of the document. When i then try to scroll back up i get a division by zero exception : When i scroll using Page Up the crash appears to happen at the call to - IOleInPlaceActiveObject:TranslateAccelerator When i scroll using the mouse the crash happens during the call to DispatchMessage Either way, the crash is happening in Internet Explorer. The stack trace shown by Delphi at the time of the exception: Is different from the stack trace shown by Jedi's

How to determine if compiling for 64-bit iOS in Xcode

匿名 (未验证) 提交于 2019-12-03 08:33:39
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Consider the following function CGSize CGSizeIntegral(CGSize size) { return CGSizeMake(ceilf(size.width), ceilf(size.height)); } CGSize actually consists of two CGFloat s, and CGFloat 's definition changes depending on the architecture: typedef float CGFloat;// 32-bit typedef double CGFloat;// 64-bit So, the above code is wrong on 64-bit systems, and needs to be updated with something like CGSize CGSizeIntegral(CGSize size) { #if 64_bit return CGSizeMake(ceil(size.width), ceil(size.height)); #else return CGSizeMake(ceilf(size.width), ceilf

Why Python `Memory Error` with list `append()` lots of RAM left

匿名 (未验证) 提交于 2019-12-03 08:30:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am building a large data dictionary from a set of text files. As I read in the lines and process them, I append(dataline) to a list. At some point the append() generates a Memory Error exception. However, watching the program run in the Windows Task Manager, at the point of the crash I see 4.3 GB available and 1.1 GB free. Thus, I do not understand the reason for the exception. Python version is 2.6.6. I guess, the only reason is that it is not able to use more of the available RAM. If this is so, is it possible to increase the allocation?