public static double[,] ParallelUncompressWithDCT(this CompressedImage image, Options options) { const int DCTSize = 8; var result = new double[image.Height, image.Width]; var blocksCount = image.Width * image.Height / (DCTSize * DCTSize); var freqsCount = Enumerable.Range(1, image.CompressionLevel).Sum(); Parallel.For(0, blocksCount, new ParallelOptions { MaxDegreeOfParallelism = options.Threads }, blockIndex => { var y = blockIndex / (image.Width / DCTSize); var x = blockIndex % (image.Width / DCTSize); var channelFreqs = new double[DCTSize, DCTSize]; var freqNum = blockIndex * freqsCount; for (var i = 0; i < DCTSize; i++) { for (var j = 0; j < DCTSize; j++) { if (i + j < image.CompressionLevel) { channelFreqs[i, j] = image.Frequences[freqNum++]; } } } var processedSubmatrix = DCTTransformer.IDCT2D(channelFreqs); processedSubmatrix.ShiftMatrixValues(128); result.SetSubmatrix(processedSubmatrix, y * DCTSize, x * DCTSize); }); return(result); }
public static double[,] UncompressWithDCT(this CompressedImage image, int DCTSize) { var result = new double[image.Height, image.Width]; var freqNum = 0; for (var y = 0; y < image.Height; y += DCTSize) { for (var x = 0; x < image.Width; x += DCTSize) { var channelFreqs = new double[DCTSize, DCTSize]; for (var i = 0; i < DCTSize; i++) { for (var j = 0; j < DCTSize; j++) { if (i + j < image.CompressionLevel) { channelFreqs[i, j] = image.Frequences[freqNum++]; } } } var processedSubmatrix = DCTTransformer.IDCT2D(channelFreqs); processedSubmatrix.ShiftMatrixValues(128); result.SetSubmatrix(processedSubmatrix, y, x); } } return(result); }
//-------------------------------------------------------------------------------------------------------------- // TODO: extending this for more messages // {"topic": "/camera/rgb/image_rect_color/compressed", // "msg": { // "header": { // "stamp": { // "secs": 1479891554, // "nsecs": 542033426}, // "frame_id": "camera_rgb_optical_frame", // "seq": 10393}, // "data": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODw}} private void DeserializeJSONstring(string message) { Debug.Log("Try to deserialize: " + message); rosPublishIncoming = (RosPublish)JsonConvert.DeserializeObject <RosMessage>(message, rosMessageConverter); //Debug.Log (rosPublish.topic); if (rosPublishIncoming.topic.Equals("/joint_states")) { //Debug.Log ("received joint states"); latestJointState = (JointState)rosPublishIncoming.msg; // TODO latency evaluation //if(testLatency){ // if(latestJointState.header.frame_id == "Latency Test"){ // TODO storing this information to a file DateTime currentTime = DateTime.Now; int secs = currentTime.Second; int nsecs = currentTime.Millisecond; //Debug.Log(""+latestJointState.header.frame_id+" "+latestJointState.header.seq+" "+latestJointState.header.stamp.secs+":"+latestJointState.header.stamp.nsecs ); //Debug.Log ("received: " + secs + ":" + nsecs); string dataLine = "" + (latestJointState.header.stamp.secs * 1000 + latestJointState.header.stamp.nsecs) + "," + (secs * 1000 + nsecs) + "," + ((secs * 1000 + nsecs) - (latestJointState.header.stamp.secs * 1000 + latestJointState.header.stamp.nsecs)); //Debug.Log ("dataline " + dataLine); latencyData.Add(dataLine); //streamWriter.WriteLine ("" + latestJointState.header.stamp.secs * 1000 + latestJointState.header.stamp.nsecs + "," + secs * 1000 + nsecs + "," + ((secs * 1000 + nsecs) - (latestJointState.header.stamp.secs * 1000 + latestJointState.header.stamp.nsecs))); //streamWriter.Close (); // } //} } // else if (rosPublishIncoming.topic.Equals("/camera/rgb/image_rect_color/compressed")) { else if (rosPublishIncoming.topic.Equals("/usb_cam/image_raw/compressed")) { latestImage = (CompressedImage)rosPublishIncoming.msg; } }
public void Dimensions() { var image = new CompressedImage(File.ReadAllBytes("TestData/valid_image.jpg")); Assert.Equal(58, image.Width); Assert.Equal(61, image.Height); }
public void UnchangedBytes() { var data = File.ReadAllBytes("TestData/valid_image.jpg"); var image = new CompressedImage(data); Assert.Equal(data, image.GetBytes()); }
public void ValidateEnabledGenericCellResultsView(RepoItemInfo cellInfo, string IsEnabledExpected) { int startX = isEnabledExpected == "true"?5:0; CompressedImage genericCellPatch = repo.RiskeerMainWindow.ContainerMultipleViews.DocumentViewContainer.FM_ResultView.TableFMResultView.Row.genericCellInfo.GetGreyWhitePatch(new Rectangle(startX, 0, 3, 17)); Imaging.FindOptions genericCellPatchOptions = Imaging.FindOptions.Default; Report.Log(ReportLevel.Info, "Validation", "Validating ContainsImage (Screenshot: 'greyPatch1' with region {X=0,Y=1,Width=3,Height=17}) on item 'cellInfo'.", cellInfo); Validate.ContainsImage(cellInfo, genericCellPatch, genericCellPatchOptions); }
private void callback(object o) { CompressedImage cm = new CompressedImage { format = new Messages.std_msgs.String("jpeg"), header = new Messages.std_msgs.Header { stamp = ROS.GetTime() } }; using (MemoryStream ms = new MemoryStream()) { PInvoke.CaptureWindow(hwnd, window_left, window_top, ms, ImageFormat.Jpeg); cm.data = ms.GetBuffer(); } pub.publish(cm); }
public CompressedImage Compress(Bitmap bmp) { if (bmp.PixelFormat != PixelFormat.Format24bppRgb) { throw new Exception($"{bmp.PixelFormat} pixel format is not supported, supported rgb24"); } var pixelsMatrix = _pixelsExtractor.Extract(bmp); var converterPixelsMatrix = MatrixRgbToYCbCrConveter.Convert(pixelsMatrix); var residueYPiece = bmp.Height % (_thinIndex * _dctSize); var residueXPiece = bmp.Width % (_thinIndex * _dctSize); var countAddYPiece = residueYPiece == 0 ? 0 : _thinIndex * _dctSize - residueYPiece; var countAddXPiece = residueXPiece == 0 ? 0 : _thinIndex * _dctSize - residueXPiece; var extendedPixelsMatrix = _matrixExtender.Extend(converterPixelsMatrix, countAddYPiece, countAddXPiece); var yCbCrchannels = _channelExtractor.Extract(extendedPixelsMatrix); var thinnedCbChannel = _matrixThinner.Thin(yCbCrchannels.CbChannel, _thinIndex); var thinnedCrChannel = _matrixThinner.Thin(yCbCrchannels.CrChannel, _thinIndex); var dctYPieces = _dctCompressor.Compress(yCbCrchannels.YChannel, _dctSize, _compressionLevel, _lumiaMatrixProvider.GetMatrix()); var dctCbPieces = _dctCompressor.Compress(thinnedCbChannel, _dctSize, _compressionLevel, _colorMatrixProvider.GetMatrix()); var dctCrPieces = _dctCompressor.Compress(thinnedCrChannel, _dctSize, _compressionLevel, _colorMatrixProvider.GetMatrix()); var result = new List <byte>(); var countYBlocksPerColorBlock = _thinIndex * _thinIndex; for (int i = 0, thinI = 0; i < dctYPieces.Length; thinI++) { for (var j = 0; j < countYBlocksPerColorBlock; j++) { result.AddRange(dctYPieces[i++]); } result.AddRange(dctCbPieces[thinI]); result.AddRange(dctCrPieces[thinI]); } var rle = Rle <byte> .Encode(result).ToArray(); Dictionary <BitsWithLength, byte> decodeTable; long bitsCount; var huf = HuffmanCodec.Encode(rle, out decodeTable, out bitsCount); var compressedImage = new CompressedImage { ThinIndex = _thinIndex, CompressionLevel = _compressionLevel, DataBytes = huf, Height = extendedPixelsMatrix.GetLength(0), Width = extendedPixelsMatrix.GetLength(1), DecodeTable = decodeTable, BitsCount = bitsCount }; return(compressedImage); }
private void callback(object o) { CompressedImage cm = new CompressedImage { format = "jpeg", header = new Header { stamp = ROS.GetTime() } }; using (MemoryStream ms = new MemoryStream()) { PInvoke.CaptureWindow(hwnd, window_left, window_top, ms, ImageFormat.Jpeg); cm.data = ms.GetBuffer(); } pub.publish(cm); }
public RosBridgeClient(bool verbose, bool imageStreaming, bool jointStates, bool testLatency, bool pointCloud) { RosBridgeClient.verbose = verbose; RosBridgeClient.imageStreaming = imageStreaming; RosBridgeClient.jointStates = jointStates; RosBridgeClient.testLatency = testLatency; latestImage = new CompressedImage(); // Buffer for latest incoming image message latestJointState = new JointState(); // Buffer for latest incoming jointState rosMessageStrings = new Queue <string> (); // Incoming message queue rosMessageConverter = new RosMessageConverter(); // Deserializing of incoming ROSmessages rosCommandQueue = new Queue <RosMessage> (); // Outgoing message queue streamWriter = new StreamWriter("latencyData.txt"); latencyData = new List <string> (); }
public static void ValidateFreightdragtoRowChart() { try { CompressedImage LineChart = repo.VisualAnalyticsVATestsVizxAsteri.BIChartOverlayPanelInfo.GetFreightDragtoRowChart(); Imaging.FindOptions options = Imaging.FindOptions.Default; options.Similarity = Configuration.Config.SIMILARITY; RepoItemInfo info = repo.VisualAnalyticsVATestsVizxAsteri.BIChartOverlayPanelInfo; Validate.ContainsImage(info, LineChart, options, "After Freight drag to RowChart data image comparision", false); Reports.ReportLog("Validate Freight drag to RowChart", Reports.ADSReportLevel.Success, null, Configuration.Config.TestCaseName); } catch (Exception ex) { throw new Exception("Failed : DragFreighttoRowDeck : " + ex.Message); } }
public static void ValidateSubtotaleColorchart() { try { repo.VisualAnalyticsVATestsVizxAsteri.Self.Maximize(); CompressedImage tableChart = repo.VisualAnalyticsVATestsVizxAsteri.PivotTableOverlayPanelInfo.GetSubTotalColorChart(); Imaging.FindOptions options = Imaging.FindOptions.Default; options.Similarity = Configuration.Config.SIMILARITY; RepoItemInfo info = repo.VisualAnalyticsVATestsVizxAsteri.PivotTableOverlayPanelInfo; Validate.ContainsImage(info, tableChart, options, "Subtotal chart image comparision", false); } catch (Exception ex) { throw new Exception("Failed : ValidateSubtotaleColorchart : " + ex.Message); } }
public static void ValidateHighlightTable() { try { repo.VisualAnalyticsVATestsVizxAsteri.Self.Maximize(); CompressedImage tableChart = repo.VisualAnalyticsVATestsVizxAsteri.PivotTableOverlayPanelInfo.GetHighlightTable(); Imaging.FindOptions options = Imaging.FindOptions.Default; options.Similarity = Configuration.Config.SIMILARITY; RepoItemInfo info = repo.VisualAnalyticsVATestsVizxAsteri.PivotTableOverlayPanelInfo; System.Threading.Thread.Sleep(1000); Validate.ContainsImage(info, tableChart, options, "Validate chart image comparision", false); } catch (Exception ex) { throw new Exception("Failed : ValidateHighlightTable : " + ex.Message); } }
public static void VerifyMemoryViewInResources() { try { if (repo.SQLdm.TableLayoutPanelInfo.Exists()) { CompressedImage rsMemory = repo.SQLdm.TableLayoutPanelInfo.GetRESMemory(); Imaging.FindOptions options = Imaging.FindOptions.Default; RepoItemInfo info = repo.SQLdm.TableLayoutPanelInfo; bool isvalid = Validate.ContainsImage(info, rsMemory, options, "Memory View image comparision in Resources Tab", false); } } catch (Exception ex) { throw new Exception("Failed : VerifyMemoryViewInResources : " + ex.Message); } }
public static void ValidateAfterClickonAbsoluteValues() { try { if (repo.VAWindow.VisulizationWindowInfo.Exists()) { CompressedImage TreeMap = repo.VAWindow.VisulizationWindowInfo.GetAbsoluteValues(); Imaging.FindOptions options = Imaging.FindOptions.Default; RepoItemInfo info = repo.VAWindow.VisulizationWindowInfo; bool isvalid = Validate.ContainsImage(info, TreeMap, options, "After click on absolute values image comparision", false); Reports.ReportLog("ValidateAfterClickonAbsoluteValues", Reports.ADSReportLevel.Success, null, Configuration.Config.TestCaseName); } } catch (Exception ex) { throw new Exception("Failed : ValidateAfterClickonAbsoluteValues : " + ex.Message); } }
public static void ValidateAfterChangetoTriangle1() { try { if (repo.VAWindow.VisualizationWindowInfo.Exists()) { CompressedImage SymboMapShape = repo.VAWindow.VisualizationWindowInfo.GetChangetoTriangleShape1(); Imaging.FindOptions options = Imaging.FindOptions.Default; RepoItemInfo info = repo.VAWindow.VisualizationWindowInfo; bool isvalid = Validate.ContainsImage(info, SymboMapShape, options, "Tree map image data validation", false); Reports.ReportLog("ValidateAfterChangetoTriangle1", Reports.ADSReportLevel.Success, null, Configuration.Config.TestCaseName); } } catch (Exception ex) { throw new Exception("Failed : ValidateAfterChangetoTriangle1 : " + ex.Message); } }
public static void ValidationAfterClickonUniformHeight() { try { if (repo.VAWindow.VisualizationWindowInfo.Exists()) { CompressedImage FunnelMap = repo.VAWindow.VisualizationWindowInfo.GetUniformHeightOption(); Imaging.FindOptions options = Imaging.FindOptions.Default; RepoItemInfo info = repo.VAWindow.VisualizationWindowInfo; bool isvalid = Validate.ContainsImage(info, FunnelMap, options, "After Click on Uniform Height image data validation", false); Reports.ReportLog("ValidationAfterClickonUniformHeight", Reports.ADSReportLevel.Success, null, Configuration.Config.TestCaseName); } } catch (Exception ex) { throw new Exception("Failed : ValidationAfterClickonUniformHeight : " + ex.Message); } }
public static void ValidateDualAxesOptionChart() { try { repo.VisualAnalyticsVATestsVizxAsteri.Self.Maximize(); if (repo.VisualAnalyticsVATestsVizxAsteri.BIChartOverlayPanelInfo.Exists()) { CompressedImage BarChart = repo.VisualAnalyticsVATestsVizxAsteri.BIChartOverlayPanelInfo.GetDualAxesOptionChart(); Imaging.FindOptions options = Imaging.FindOptions.Default; options.Similarity = Configuration.Config.SIMILARITY; RepoItemInfo info = repo.VisualAnalyticsVATestsVizxAsteri.BIChartOverlayPanelInfo; Validate.ContainsImage(info, BarChart, options, "DualAxes Option Chart data image comparision", false); } } catch (Exception ex) { throw new Exception("Failed : ValidateDualAxesOptionChart : " + ex.Message); } }
public static void ValidateTreeMapFile() { try { repo.VAWindow.Self.Maximize(); if (repo.VAWindow.VisulizationWindowInfo.Exists()) { CompressedImage TreeMap = repo.VAWindow.VisulizationWindowInfo.GetTreeMapData(); Imaging.FindOptions options = Imaging.FindOptions.Default; RepoItemInfo info = repo.VAWindow.VisulizationWindowInfo; bool isvalid = Validate.ContainsImage(info, TreeMap, options, "Tree map image data validation", false); Reports.ReportLog("ValidateTreeMapFile", Reports.ADSReportLevel.Success, null, Configuration.Config.TestCaseName); } } catch (Exception ex) { throw new Exception("Failed : ValidateTreeMapFile : " + ex.Message); } }
public void ImageContent() { const string path = "TestData/valid_image.jpg"; var compressed = new CompressedImage(File.ReadAllBytes(path)); using (var fileBitmap = new Bitmap(path)) using (Bitmap fromCompressed = (Bitmap)compressed.Image) { for (int column = 0; column < fileBitmap.Width; column++) { for (int row = 0; row < fileBitmap.Height; row++) { Assert.Equal( fileBitmap.GetPixel(column, row), fromCompressed.GetPixel(column, row)); } } } }
public static void ValidateMergedSharedscaleChart() { try { repo.VisualAnalyticsVATestsVizxAsteri.Self.Maximize(); if (repo.VisualAnalyticsVATestsVizxAsteri.BIChartOverlayPanelInfo.Exists()) { CompressedImage LineChart = repo.VisualAnalyticsVATestsVizxAsteri.BIChartOverlayPanelInfo.GetMergeSharedscaleOption(); Imaging.FindOptions options = Imaging.FindOptions.Default; options.Similarity = Configuration.Config.SIMILARITY; RepoItemInfo info = repo.VisualAnalyticsVATestsVizxAsteri.BIChartOverlayPanelInfo; Validate.ContainsImage(info, LineChart, options, " MergeShared scale Option data validate", false); } } catch (Exception ex) { throw new Exception("Failed : ValidateMergedSharedscaleChart : " + ex.Message); } }
public static void ValidateUnstackedOptionChart() { try { repo.VATest.Self.Maximize(); if (repo.VATest.BIChartOverlayPanelInfo.Exists()) { CompressedImage AreaChart = repo.VATest.BIChartOverlayPanelInfo.GetUnstackedOption(); Imaging.FindOptions options = Imaging.FindOptions.Default; options.Similarity = Configuration.Config.SIMILARITY; RepoItemInfo info = repo.VATest.BIChartOverlayPanelInfo; Validate.ContainsImage(info, AreaChart, options, "Unstacked Option data image comparision", false); } } catch (Exception ex) { throw new Exception("Failed : ValidateUnstackedOptionChart : " + ex.Message); } }
public static void ValidateSliderMinimumChart() { try { repo.VATest.Self.Maximize(); if (repo.VATest.BIChartOverlayPanelInfo.Exists()) { CompressedImage ShapeChart = repo.VATest.BIChartOverlayPanelInfo.GetSlidermovetoMinimum(); Imaging.FindOptions options = Imaging.FindOptions.Default; options.Similarity = Configuration.Config.SIMILARITY; RepoItemInfo info = repo.VATest.BIChartOverlayPanelInfo; Validate.ContainsImage(info, ShapeChart, options, "After Slider move to Minimum ShapeChart image comparision", false); } } catch (Exception ex) { throw new Exception("Failed : ValidateSliderMinimumChart : " + ex.Message); } }
public static void ValidateVAtestsdataWindow() { try { if (repo.VisualAnalyticsVATestsVizxAsteri.StartWindowInfo.Exists()) { CompressedImage tableChart = repo.VisualAnalyticsVATestsVizxAsteri.StartWindowInfo.GetVizxDataWindow(); Imaging.FindOptions options = Imaging.FindOptions.Default; options.Similarity = Configuration.Config.SIMILARITY; RepoItemInfo info = repo.VisualAnalyticsVATestsVizxAsteri.StartWindowInfo; System.Threading.Thread.Sleep(5000); Validate.ContainsImage(info, tableChart, options, "VA-tests.vizx data image comparision", false); } } catch (Exception ex) { throw new Exception("Failed : ValidateVAtestsdataWindow : " + ex.Message); } }
public Bitmap Decompress(CompressedImage compressedImage) { var unHuf = HuffmanCodec.Decode(compressedImage.DataBytes, compressedImage.DecodeTable, compressedImage.BitsCount); var unRle = Rle <byte> .Decode(unHuf).ToArray(); var yDct = new List <double>(); var cbDct = new List <double>(); var crDct = new List <double>(); var countYBlocks = compressedImage.ThinIndex * compressedImage.ThinIndex; var cellsToBlock = compressedImage.CompressionLevel; for (var i = 0; i < unRle.Length;) { for (var j = 0; j < countYBlocks * cellsToBlock; j++) { yDct.Add(unRle[i++]); } for (var j = 0; j < cellsToBlock; j++) { cbDct.Add(unRle[i++]); } for (var j = 0; j < cellsToBlock; j++) { crDct.Add(unRle[i++]); } } var yDctBlocks = DevideIntoPiece(yDct, compressedImage.CompressionLevel); var cbDctBlocks = DevideIntoPiece(cbDct, compressedImage.CompressionLevel); var crDctBlocks = DevideIntoPiece(crDct, compressedImage.CompressionLevel); var yChannel = _dctDecompressor.Decompress(yDctBlocks, _dctSize, compressedImage.Height, compressedImage.Width, _lumiaMatrixProvider.GetMatrix()); var thinnedCbChannel = _dctDecompressor.Decompress(cbDctBlocks, _dctSize, compressedImage.Height / compressedImage.ThinIndex, compressedImage.Width / compressedImage.ThinIndex, _colorMatrixProvider.GetMatrix()); var thinnedCrChannel = _dctDecompressor.Decompress(crDctBlocks, _dctSize, compressedImage.Height / compressedImage.ThinIndex, compressedImage.Width / compressedImage.ThinIndex, _colorMatrixProvider.GetMatrix()); var cbChannel = _pieceMatrixExtender.Extend(thinnedCbChannel, compressedImage.ThinIndex); var crChannel = _pieceMatrixExtender.Extend(thinnedCrChannel, compressedImage.ThinIndex); var yCbCrChannels = new YCbCrChannels(yChannel, cbChannel, crChannel); var yCbCrPixels = _iChannelsPacker.Pack(yCbCrChannels, compressedImage.Height, compressedImage.Width); var matrixRgbPixels = MatrixYCbCrToRgbConverter.Convert(yCbCrPixels); var bmp = _bitmapBuilder.Build(matrixRgbPixels); return(bmp); }
public static void ValidateDragProducttoShapeChart() { try { repo.VATest.Self.Maximize(); if (repo.VATest.BIChartOverlayPanelInfo.Exists()) { CompressedImage ShapeChart = repo.VATest.BIChartOverlayPanelInfo.GetDragProducttoShapeDeck(); Imaging.FindOptions options = Imaging.FindOptions.Default; options.Similarity = Configuration.Config.SIMILARITY; RepoItemInfo info = repo.VATest.BIChartOverlayPanelInfo; System.Threading.Thread.Sleep(5000); Validate.ContainsImage(info, ShapeChart, options, "After Drag Product to ShapeDeck ShapeChart image comparision", false); } } catch (Exception ex) { throw new Exception("Failed : ValidateDragProducttoShapeChart : " + ex.Message); } }
public void sample() { var sw = Stopwatch.StartNew(); var fileName = @"sample.bmp"; var compressedFileName = fileName + ".compressed." + CompressionQuality; var uncompressedFileName = fileName + ".uncompressed." + CompressionQuality + ".bmp"; using (var fileStream = File.OpenRead(fileName)) using (var bmp = (Bitmap)Image.FromStream(fileStream, false, false)) { var imageMatrix = (Matrix)bmp; sw.Start(); var compressionResult = Program.Compress(imageMatrix, CompressionQuality); compressionResult.Save(compressedFileName); } var compressedImage = CompressedImage.Load(compressedFileName); var uncompressedImage = Program.Uncompress(compressedImage); var resultBmp = (Bitmap)uncompressedImage; resultBmp.Save(uncompressedFileName, ImageFormat.Bmp); }
private void mapcb(CompressedImage msg) { lastimage = msg; textureMutex.Set(); }
private void ProcessValidateItems(ElementInfo elementInfo, IList <ValidationRecordItem> recordedItems) { FlushRecording(); AgentResponse agentResponse = new AgentResponse(); agentResponse.messageType = AgentResponse.MessageType.CAPTURE_STEP_REPONSE; RanorexStepCaptureReponse captureResponse = new RanorexStepCaptureReponse(); RanorexStepExecutionResponse executionResponse = new RanorexStepExecutionResponse(); agentResponse.stepCaptureReponse = captureResponse; Dictionary <string, object> properties = new Dictionary <string, object>(); Dictionary <string, string> attributes = new Dictionary <string, string>(); Dictionary <string, object> structuredData = new Dictionary <string, object>(); foreach (ValidationRecordItem item in recordedItems) { if (item.Action == ValidationAction.NotExists || item.Action == ValidationAction.Exists) { continue; } if (elementInfo == null) { elementInfo = item.Info; } if (item.Action == ValidationAction.CompareImage || item.Action == ValidationAction.ContainsImage) { ImageSearchProperties searchProps = item.ImageBasedLocation; Rectangle imgRect = searchProps.ImageSelectionRectangle; CompressedImage image = elementInfo.LiveElementOrSnapshot.CaptureCompressedImage(); properties.Add("image", image.ToBase64String()); properties.Add("imageAction", item.Action.ToString()); properties.Add("clipX", imgRect.X); properties.Add("clipY", imgRect.Y); properties.Add("clipWidth", imgRect.Width); properties.Add("clipHeight", imgRect.Height); structuredData.Add("imageValidated", true); } else { executionResponse.message += item.MatchName + "=" + item.MatchValue + "\n"; attributes.Add(item.MatchName, item.MatchValue); } } properties.Add("attributes", attributes); structuredData.Add("attributes", attributes); captureResponse.action = "Get Attribute"; string absolutePath = elementInfo.Path.ToResolvedString(); if (absolutePath.StartsWith("/mobileapp")) { absolutePath = Regex.Replace(absolutePath, "/mobileapp\\[@devicename='[^\\/]*'\\]", "/mobileapp"); } captureResponse.target = absolutePath; captureResponse.properties = properties; executionResponse.structuredData = structuredData; executionResponse.success = true; agentResponse.stepExecutionResponse = executionResponse; agentServer.SendMessage(agentResponse); }
public override RanorexStepExecutionResponse Execute(Dictionary <string, object> arguments) { RanorexStepExecutionResponse stepResponse = new RanorexStepExecutionResponse(); try { RepoItemInfo repoItemInfo = null; Ranorex.Unknown adapter = null; string target = (string)arguments.GetValueOrDefault <string, object>("target"); int timeout = Convert.ToInt32(arguments.GetValueOrDefault <string, object>("timeout")); bool retrieveImage = (bool)arguments.GetValueOrDefault <string, object>("retrieveImage"); System.Collections.IDictionary imageProps = (System.Collections.IDictionary)arguments["imageValidationProperties"]; System.Collections.IList attributes = (System.Collections.IList)arguments["attributes"]; if (timeout == default(int)) { timeout = 10000; } if (target != default(string)) { repoItemInfo = CreateItemInfo(repo, target, timeout); adapter = CreateAdapter(repoItemInfo); Dictionary <string, object> structuredData = new Dictionary <string, object>(); Dictionary <string, object> receivedAttributes = new Dictionary <string, object>(); foreach (System.Collections.IDictionary attribute in attributes) { string name = (string)attribute["header"]; string value = adapter.Element.GetAttributeValueText(name); stepResponse.message += name + "=" + value + "\n"; receivedAttributes.Add(name, value); } structuredData.Add("attributes", receivedAttributes); if (imageProps != null) { string validationMode = (string)imageProps["validationMode"]; if (validationMode != "NONE") { string image = (string)imageProps["imageData"]; int rectX = Convert.ToInt32(imageProps["clipX"]); int rectY = Convert.ToInt32(imageProps["clipY"]); int rectWidth = Convert.ToInt32(imageProps["clipWidth"]); int rectHeight = Convert.ToInt32(imageProps["clipHeight"]); try { CompressedImage compressedImage = new CompressedImage(image); using (Bitmap bitmap = Imaging.Crop(compressedImage.Image, new Rectangle(rectX, rectY, rectWidth, rectHeight))) { compressedImage = new CompressedImage(bitmap); } if (validationMode == "CONTAINS_IMAGE") { Validate.ContainsImage(repoItemInfo, compressedImage, Imaging.FindOptions.Default); } else if (validationMode == "COMPARE_IMAGE") { Validate.ContainsImage(repoItemInfo, compressedImage, Imaging.FindOptions.Default); } structuredData.Add("imageValidated", "true"); stepResponse.message += "#imageValidated=true\n"; } catch (ValidationException e) { structuredData.Add("imageValidated", "false"); stepResponse.message += "#imageValidated=false\n"; } } } stepResponse.structuredData = structuredData; if (retrieveImage) { stepResponse.image64 = GetImage64(adapter); } } else { throw new Exception("No target defined!"); } stepResponse.success = true; } catch (Exception e) { stepResponse.message = "Ranorex Exception: " + e.Message; stepResponse.success = false; } return(stepResponse); }