I'm trying to improve a real time detection using haarcascade, I've digged into the haarcascade's file to see that the HasCuda is not working, or the gpucascadeclassifier is not working, making the application unresponsive, I'm using a Nvidia 980 GTX (so it's not a hardware problem)
Sample Code:
if (GpuInvoke.HasCuda)
{
using (var car = new GpuCascadeClassifier(carFileName))
{
using (var gpuImage = new GpuImage<Bgr, byte>(image))
using (var gpuGray = gpuImage.Convert<Gray, Byte>())
{
var carRegion = car.DetectMultiScale(gpuGray, 1.1, 10, Size.Empty);
cars.AddRange(carRegion);
}
}
}
Related
i'm using an Iphone 10 with ios 15.3.1,Zxing version = 2.4.1, compiling the xamarin project in windows. I been trying to make a qr scanner with zxing for ios android, but when i run my app in ios, it won't go to the onResult event. I've tried with a lot of methods of doing this, but nothing seems to work. The camera shows, but the result never comes truh. ¿Does someone have any idea why this is happening? I also tried apps from other devs that are using zxing and it also dosen't work. but when i scan with the camera app it works.
async void OnButtonClickedAsync(object sender, System.EventArgs e)
{
var options = new ZXing.Mobile.MobileBarcodeScanningOptions
{
CameraResolutionSelector = HandleCameraResolutionSelectorDelegate
};
MobileBarcodeScanner scanner = new MobileBarcodeScanner();
//scanner.TopText = "Hold camera up to barcode to scan";
//scanner.BottomText = "Barcode will automatically scan";
//scanner.UseCustomOverlay = false;
scanner.FlashButtonText = "Flash";
scanner.CancelButtonText = "Cancel";
scanner.Torch(true);
scanner.AutoFocus();
var result = await scanner.Scan(options);
HandleScanResult(result);
}
void HandleScanResult(ZXing.Result result)
{
if (result != null && !string.IsNullOrEmpty(result.Text))
scanResultText.Text = result.Text;
}
CameraResolution HandleCameraResolutionSelectorDelegate(List<CameraResolution> availableResolutions)
{
//Don't know if this will ever be null or empty
if (availableResolutions == null || availableResolutions.Count < 1)
return new CameraResolution() { Width = 800, Height = 600 };
//Debugging revealed that the last element in the list
//expresses the highest resolution. This could probably be more thorough.
return availableResolutions[availableResolutions.Count - 1];
}
I compiled using a mac and it worked fine, must be a bug of visual studio on windows.
I have custom an camera app in Windows Phone 8. I need add a watermark image to each frame from camera capture and then record to a video.
I can customise each frame from the preview using the following code:
int[] pixelData = new int[(int)(camera.PreviewResolution.Width * camera.PreviewResolution.Height)];
camera.GetPreviewBufferArgb32(pixelData);
return pixelData;
and write it back to the preview.
my problem is that while I can show the frames on the screen while the user is recording a movie using the camera I cant find a working solution for WP8 to encode the frames and audio to save to a file.
I already tried opencv,libav and others without success,
if anyone can point me to the right direction it would be greatly appreciated.
You can do it like this.
private void GetCameraPicture_Click(object sender, RoutedEventArgs e)
{
Microsoft.Phone.Tasks.CameraCaptureTask cameraCaptureTask = new Microsoft.Phone.Tasks.CameraCaptureTask();
cameraCaptureTask.Completed += cct_Completed;
cameraCaptureTask.Show();
}
try
{
if (e.TaskResult == Microsoft.Phone.Tasks.TaskResult.OK)
{
var imageStream = e.ChosenPhoto;
var name = e.OriginalFileName;
using (MemoryStream mem = new MemoryStream())
{
TextBlock tb = new TextBlock() { Text = DateTime.Now.ToString("dd MMM yyyy, HH:mm"), Foreground = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0)), FontSize = 40 };
BitmapImage finalImage = new BitmapImage();
finalImage.SetSource(imageStream);
WriteableBitmap wbFinal = new WriteableBitmap(finalImage);
wbFinal.Render(tb, null);
wbFinal.Invalidate();
wbFinal.SaveJpeg(mem, wbFinal.PixelWidth, wbFinal.PixelHeight, 0, 100);
mem.Seek(0, System.IO.SeekOrigin.Begin);
MediaLibrary lib = new MediaLibrary();
lib.SavePictureToCameraRoll("Copy" + name, mem.ToArray());
}
}
}
catch (Exception exp) { MessageBox.Show(exp.Message); }
Hope it may help you.
I have an app that is built from Flash CS5.5, exported using AIR3.1 and distributed through the Enterprise setup from Apple (allows me to bypass appstore approval).
I'm now trying to have a PDF (generated using AlivePDF) exported somehow into the iPad, either into iBooks or just have it opened in Safari.
This is what I'm using for my desktop version of the app. Although the scripting is very messy it gets the job done. I just don't know how to convert this over and make it work on an iPad
//Populate listbox component from array
function noEmpty(item:*, index:int, array:Array):Boolean{
return item != undefined;
}
for(var i:int = 0; i < MovieClip(root).selectedProducts.length; i++) {
if(MovieClip(root).selectedProducts[i] != undefined){
selectedProductsText.dataProvider.addItem({label: MovieClip(root).selectedProducts[i]});
}
}
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.size = 20;
myTextFormat.font = "Arial";
myTextFormat.color = 0x000000;
myTextFormat.leftMargin = 30;
selectedProductsText.rowHeight = 40;
selectedProductsText.setRendererStyle("textFormat", myTextFormat);
//AlivePDF, generate PDF
import org.alivepdf.pdf.PDF;
import org.alivepdf.layout.Orientation;
import org.alivepdf.layout.Size;
import org.alivepdf.layout.Unit;
import org.alivepdf.display.Display;
import org.alivepdf.saving.Method;
import org.alivepdf.fonts.FontFamily;
import org.alivepdf.fonts.Style;
import org.alivepdf.colors.RGBColor;
import com.adobe.images.*;
function convertString(_value:String):String
{
var returnString:String = "";
var _chr:String = String.fromCharCode(13);
var tempArray:Array = _value.split(_chr);
for(var i:uint = 0; i < tempArray.length; i++)
{
returnString += tempArray[i] + "\n";
}
return returnString;
}
var pdf:PDF = new PDF();
pdf.setDisplayMode (Display.REAL);
pdf.addPage();
pdf.writeText(7, convertString( MovieClip(root).selectedProducts.filter(noEmpty).join('\n') ));
var buffer:ByteArray = pdf.save(Method.LOCAL);
var file:FileReference = new FileReference();
//save PDF button
btnPdf.addEventListener( MouseEvent.CLICK, generatePDF );
function generatePDF ( e:MouseEvent )
{
file.save(buffer, "Product Selection List.pdf");
}
Having done some work with AIR for iOS I would say your issue will be that you need to change how the file is saved and stored on the device.
You need to save the file to the apps storage directory with something like this that I used to store a jpg image:
f = File.documentsDirectory.resolvePath(imagename+".jpg");
stream = new FileStream();
stream.open(f, FileMode.WRITE);
j = new JPGEncoder(80);
bytes = new ByteArray();
bytes = j.encode(snapShot.bitmapData);
stream.writeBytes(bytes, 0, bytes.bytesAvailable);
stream.close();
I'm not sure how or if it's even possible through AIR to send the pdf to iBooks. You could use StageWebView within your app though to display the PDF.
I have a excel sheet with one chart which is the source. My target is a powerpoint presentation with 3 slides. I need to update slide #3 with the Chart in the excel file.
After executing the application and when I try to open the pptx file I get a "Powerpoint found a problem with content". After I repair I notice that I always get a blank slide in Slide #2 which shows I am not updating the correct slide.
What should I do to go to the slide based on slide no. (I don't have chart titles in the powerpoint slide and the excel chart) and why am I getting a invalid content error.
I Would greatly appreciate your help. Thanks
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using OpenXmlPkg = DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Presentation;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
namespace ExportChart
{
class Program
{
static void Main(string[] args)
{
string SourceFile = "Projected Sales.xlsx";
string TargetFile = "Projected Sales.pptx";
string targetppt = "Generatedppt.pptx";
ChartPart chartPart;
ChartPart newChartPart;
SlidePart slidepartbkMark = null;
string chartPartIdBookMark = null;
File.Copy(TargetFile, targetppt, true);
//Powerpoint document
using (OpenXmlPkg.PresentationDocument pptPackage = OpenXmlPkg.PresentationDocument.Open(targetppt, true))
{
OpenXmlPkg.PresentationPart presentationPart = pptPackage.PresentationPart;
var secondSlidePart = pptPackage.PresentationPart.SlideParts.Skip(1).Take(1);
foreach (var slidepart in pptPackage.PresentationPart.SlideParts)
{
slidepartbkMark = slidepart;
if (slidepart.GetPartsCountOfType<ChartPart>() != 0)
{
chartPart = slidepart.ChartParts.First();
chartPartIdBookMark = slidepart.GetIdOfPart(chartPart);
slidepart.DeletePart(chartPart);
slidepart.Slide.Save();
}
//return;
}
newChartPart = slidepartbkMark.AddNewPart<ChartPart>(chartPartIdBookMark);
ChartPart saveXlsChart = null;
using (SpreadsheetDocument xlsDocument = SpreadsheetDocument.Open(SourceFile.ToString(), true))
{
WorkbookPart xlsbookpart = xlsDocument.WorkbookPart;
foreach (var worksheetPart in xlsDocument.WorkbookPart.WorksheetParts)
{
if (worksheetPart.DrawingsPart != null)
if (worksheetPart.DrawingsPart.ChartParts.Any())
{
saveXlsChart = worksheetPart.DrawingsPart.ChartParts.First();
}
}
newChartPart.FeedData(saveXlsChart.GetStream());
slidepartbkMark.Slide.Save();
xlsDocument.Close();
pptPackage.Close();
}
}
}
}
}
If there is anybody who is looking how to identify a slide with a slide number you need to do the following
//Get the relationship id
SlideIdList s = documentPart.Presentation.SlideIdList;
SlideId nslideid = (SlideId)s.ElementAt(slideno-1); //slide no is the number of the slide
string slidRelId = nslideid.RelationshipId;
Next iterate through each slide using a loop. Within the foreach loop add the following code to see if a slide has a particular relationship id
// get the relationshipid of the current slide
string thisSlideno = documentPart.GetIdOfPart(slidePart);
if (thisSlideno == slidRelId)
{
//do your actions
}
I hope this is helpful
I'm loading an SWF animation and want to display it in multiple places concurrently, but the only way I could figure out how to do that is to load it every time I display it, as seen here:
private function playSounds():void {
for (var i:Number = 0; i < 14; i++)
{
for (var a:Number = 0; a < 16; a++)
{
if (boxes[i][a].x == linePos && boxes[i][a].selected == true && played[i][a] == false)
{
played[i][a] = true;
MovieClip();
var swf:URLRequest = new URLRequest("../assets/glow2.swf")
var glow:Loader = new Loader()
glow.load(swf)
glow.x = boxes[i][a].x - 25*0.7;
glow.y = boxes[i][a].y - 27*0.7;
glow.scaleX = 0.7;
glow.scaleY = 0.7;
this.addChild(glow);
glows.push(glow)
glowTime.push(0)
var sc:SoundChannel = new SoundChannel();
sc = (sounds[i] as Sound).play();
}
}
}
}
This is very very slow when it's being displayed more than, say, 5 times at once so I'm wondering if there's a way to only have to load it once and use it in multiple places.
You have the content property of the Loader.
Thus, load once, use the content many times.
edit: you may want to add a listener to know when the loading completes, before you use the loaded content:
addEventListener(Event.COMPLETE, completeHandler);
edit2:
var mc1:MovieClip = new MovieClip();
var mc2:MovieClip = new MovieClip();
var my_Loader:Loader = new Loader();
mc1.addChild(my_Loader);
mc2.addChild(my_Loader);
(haven't tried though).
One quick workaround is to create a second loader and pass the loaded bytes to that via the loadBytes() method:
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(Event.COMPLETE,ready);
l.load(new URLRequest("../assets/glow2.swf"));
function ready(event:Event):void{
var mc:MovieClip = event.currentTarget.content as MovieClip;
var clone:Loader = new Loader();
clone.loadBytes(event.currentTarget.bytes);
addChild(mc);
addChild(clone);
clone.x = 100;
}
This will work in most cases. In some cases you should be able to get away with something as simple as:
var clone:MovieClip = MovieClip(new mc.constructor());
And there is also a 3rd option: 'blitting' your moviclip, which means you'll store one or more (depending how many MoveClip frames you need to cache) of BitmapData objects in memory which will draw() from the source MovieClip you want to draw (in multiple locations at the same time).
The loadBytes approach achieves what the question suggests: creates a copy of the Loader, so it re-uses the bytes loaded, but initializes new content, so uses memory for that.
If this is not what you need, caching the MovieClip using BitmapData is your best bet.