I am using Logitech pro9000 HD webcam. Which have 2 mp zeiss lence and can capture HD video etc. blaa blaa
My code [not exactly the same but integrated in single function.
Now the problem if I use resolution up to 1600 x 1200 everything works fine. And received byte size as follows
for 640 x 480 VideoHeader.dwBytesUsed are 921600
for 1600 x 1200 VideoHeader.dwBytesUsed are 5760000
from 1600 x 1200 to 3264 x 2448 VideoHeader.dwBytesUsed are 5760000
But for higher resolution from 1600 x 1200 the byte size is same as 1600 x 1200 but my program can’t covert that data to bitmap I event try to set size of bitmap to 1600 x 1200 but nothing works I get only fuzzy at bottom or stretched multiple images at bottom of preview bitmap.
I know this is called interpolation
My question is where the interpolations is implemented actually in driver which I am accessing or the camera application given by company
Means do I am getting the interpolated data or I have to implement the algorithm in my program.
What confused me is if driver is still returning 1600 x 1200 images and software from Logitech is interpolating image to 3264 x 2448 size if this is a case then why I am not getting the 1600 x 1200 image from device event I set video format at init code to 3264 x 2448
[I have set bit to 24 and camera is using Format24bppRgb Pixel Format]
can anyone help me !....
my code is
Private Sub FrameCallBack(ByVal lwnd As IntPtr, ByVal lpVHdr As IntPtr)
Dim _SnapSize As Size = New Size(640, 480)
'Dim _SnapSize As Size = New Size(1600, 1200)
Dim _SnapSize As Size = New Size(3264, 2448)
Dim VideoHeader As New Avicap.VIDEOHDR
Dim VideoData(-1) As Byte
VideoHeader = CType(Avicap.GetStructure(lpVHdr, VideoHeader), Avicap.VIDEOHDR)
VideoData = New Byte(VideoHeader.dwBytesUsed - 1) {}
Marshal.Copy(VideoHeader.lpData, VideoData, 0, VideoData.Length)
Dim _SnapFormat As System.Drawing.Imaging.PixelFormat = PixelFormat.Format24bppRgb
Dim outBit As Bitmap
If Me.IsValidData Then
outBit = New Bitmap(_SnapSize.Width, _SnapSize.Height, _SnapFormat)
Dim bitData As BitmapData
bitData = outBit.LockBits(New Rectangle(Point.Empty, _SnapSize), ImageLockMode.WriteOnly, _SnapFormat)
outBit.UnlockBits(bitData)
GC.Collect()
GC.WaitForPendingFinalizers()
End If
End Sub
First really sorry that I completely forgot about this question
The answer is - these structures are for native APIs.
My camera was 2 mega pixel lens and I was getting proper image at resolution of 1600 x 1200
The math is simple
1600 x 1200 = 1920000 Total Pixels
Pixel format is 24 bpp means 3 bytes for each pixel total size of image is 5760000
This lens can no longer produce data more than 2 mb that’s why 1600x1200 is the hardware resolution limit for this camera and hardware is not responsible for interpolation for higher resolution image that’s why I have to do it manually after getting original image from camera.
This is what exactly I did; I capture image of 1600x1200 and write image processing algos to create interpolation and improving quality of that image.
Project was creating a cheap book scanning device for document scanning. Was done successfully and in use by our clients.
Related
I have a two-part question,
1) I have an MP4 file and want to generate it's audio waveform.
2) I have another MP4 file which has audio at channel [0] and channel [1] and a video track too, I want to generate waveforms for both channels as separate images.
How can I achieve both of the above by using GSteamer?
Is the raw audio in 16-bit or 32-bit format? What is the sample rate (44100 hz) and what is time duration?
Anyways assuming 44.1khz at 10 second duration... since you can't draw 44 thousand samples as pixel width so choose a final display size (eg: width = 800px and height = 600px) and do math :
//# is (samplerate / duration) / width...
(44100 / 10) / 800 = 551;
After reading first 2 values, you will jump ahead by 551 bytes and repeat until total of (.
So in your raw data starting from pos = 0;...
1) Check this and next sample, then multiply their values together (sample[pos] x sample[pos+1]).
2) Take that result and divide by 65335 (maximum value of 16-bits or 2 bytes). That's the final value of your first sample or point.
3) Draw a line to fit according to image height (eg: 600px) so if sample = 0.83 then:
line_height = (600 x 0.83); //# gives 498 as line height
line_count += 1; //# add plus 1 to line count (stop when it reaches 800)
4) Skip ahead from position [pos] by +551 bytes and repeat step (1) until line_count == 800;
I am new to android studio , i have set layout of xxxhdpi devices . Devices Pixel XL, Nexus 6, Nexus 6p have size(1440*2560) 560 dpi and their layouts are fine but Pixel XL 2 has size (1440*2880) 560 dpi layout is pushing downward , how to reduce difference for that?
For keeping all these ‘screen resolution and density’ combinations simpler, Android wants us to consider them as DIP or DP units (Density Independent Pixels), which are corrected for density. For designing/development perspective, Android treats any device as its DP unit size instead of its actual pixel size. Android calculates DP size by using the following formula:
DP size of any device is (actual resolution/density conversion factor).
Density conversion factor for density buckets are as follows:
ldpi: 0.75
mdpi: 1.0 (base density)
hdpi: 1.5
xhdpi: 2.0
xxhdpi: 3.0
xxxhdpi: 4.0
Examples of resolution/density conversion to DP:
ldpi device of 240 X 320 px will be of 320 X 426.66 DP.
240 / 0.75 = 320 dp
320 / 0.75 = 426.66 dp
xxhdpi device of 1080 x 1920 pixels (Samsung S4, S5) will be of 360 X 640 dp.**
1080 / 3 = 360 dp
1920 / 3 = 640 dp
follow this link, http://vinsol.com/blog/2014/11/20/tips-for-designers-from-a-developer/
Python developers
I am working on spectroscopy in a university. My experimental 1-D data sometimes shows "cosmic ray", 3-pixel ultra-high intensity, which is not what I want to analyze. So I want to remove this kind of weird peaks.
Does anybody know how to fix this issue in Python 3?
Thanks in advance!!
A simple solution could be to use the algorithm proposed by Whitaker and Hayes, in which they use modified z scores on the derivative of the spectrum. This medium post explains how it works and its implementation in python https://towardsdatascience.com/removing-spikes-from-raman-spectra-8a9fdda0ac22 .
The idea is to calculate the modified z scores of the spectra derivatives and apply a threshold to detect the cosmic spikes. Afterwards, a fixer is applied to remove the spike points and replace it by the mean values of the surrounding pixels.
# definition of a function to calculate the modified z score.
def modified_z_score(intensity):
median_int = np.median(intensity)
mad_int = np.median([np.abs(intensity - median_int)])
modified_z_scores = 0.6745 * (intensity - median_int) / mad_int
return modified_z_scores
# Once the spike detection works, the spectrum can be fixed by calculating the average of the previous and the next point to the spike. y is the intensity values of a spectrum, m is the window which we will use to calculate the mean.
def fixer(y,m):
threshold = 7 # binarization threshold.
spikes = abs(np.array(modified_z_score(np.diff(y)))) > threshold
y_out = y.copy() # So we don't overwrite y
for i in np.arange(len(spikes)):
if spikes[i] != 0: # If we have an spike in position i
w = np.arange(i-m,i+1+m) # we select 2 m + 1 points around our spike
w2 = w[spikes[w] == 0] # From such interval, we choose the ones which are not spikes
y_out[i] = np.mean(y[w2]) # and we average the value
return y_out
The answer depends a on what your data looks like: If you have access to two-dimensional CCD readouts that the one-dimensional spectra were created from, then you can use the lacosmic module to get rid of the cosmic rays there. If you have only one-dimensional spectra, but multiple spectra from the same source, then a quick ad-hoc fix is to make a rough normalisation of the spectra and remove those pixels that are several times brighter than the corresponding pixels in the other spectra. If you have only one one-dimensional spectrum from each source, then a less reliable option is to remove all pixels that are much brighter than their neighbours. (Depending on the shape of your cosmics, you may even want to remove the nearest 5 pixels or something, to catch the wings of the cosmic ray peak as well).
I'm building a VoIP application. If I take the slider value and just multiply audio samples by it, I get incorrect, nonlinear sounding results. What's the correct formula to get smooth results?
The correct formula is the decibel formula solved for Prms. Here's example code in C:
// level is 0 to 1, silence is dBFS at level 0
void AdjustVolume(int16_t* buffer, size_t length, float level, float silence = -96)
{
float factor = pow(10.0f, (1 - level) * silence / 20.0f);
for (size_t i = 0; i < length; i++)
buffer[i] = static_cast<int16_t>(buffer[i] * factor);
}
There's one tweakable: silence. It's the amount of noise when there's no sound. Or: the loudness level below which you can't hear the sound because of the background noise. The theoretical maximum silence for 16 bit audio samples is -96 dB (a sample with integer value of 1 out of 32767). In the real world however, there's background noise produced by the audio equipment and the surroundings of the listener, so you might want to pick a noisier silence level, like -30 dB or something. Picking the correct silence value will maximize the useful surface area of your volume slider, or minimize the amount of slider area where no perceptible change in volume occurs.
I am trying get 3 new random floats into my pixel shader for each pixel. Based on what I have read here, here, and also here, I believe that I need to generate a large texture containing random RGB values and then during each draw call randomly generate a couple of texture coordinate offset values to produce a pseudo-random effect. Is the only way to do this through the LockRect and UnlockRect API? I hope not.
They only way I have found to do this is the lock and unlock rectangle method. But it is much easier then I initially thought. Here is how I filled the texture.
'Create Random texture for dithering shader
rando = New Random()
randomText = New Texture(device, 1000, 1000, 1, Usage.Dynamic,
Format.A16B16G16R16, Pool.Default)
'89599
'89510
Dim data(1000 * 1000 * 8 + 1000 * 63 + 936) As Byte
rando.NextBytes(data)
Dim dataBox As DataRectangle =
randomText.GetSurfaceLevel(0).LockRectangle(LockFlags.None)
dataBox.Data.Seek(0, IO.SeekOrigin.Begin)
dataBox.Data.Write(data, 0, data.Length)
dataBox.Data.Close()
As you can see from the code I had to add a lot of extra bytes to completely fill the texture with random values. I used a 1000 x 1000 64bit texture so you would think I would need 1000*1000*8 Bytes of data but I need an extra 63936 Bytes to fill the texture and I am not sure why. But it seems to work for my needs.